2017-02-22 8 views
0

django 프로젝트는 다음 코드를 사용하여 파일을 다운로드합니다. 클라이언트 컴퓨터에 IDM이 설치되어 있으면 IDM이 설치되어 있지 않으면 작동하지 않습니다. 나는이 이상한 이유를 찾을 수 없었다. 인 download.html에 대한Django 다운로드는 브라우저에서 작동하지 않지만 인터넷 다운로드 관리자 (IDM)가 설치된 컴퓨터에서 정상적으로 작동합니다.

views.py

def somefunction(): 
     something something 
     return render(request, 
         'something/download/download.html', 
         {'pdf_file_location': pdf_file_location}) 
def download(request): 
if not request.user.is_authenticated(): 
    return render(request, 'login/login/login.html') 
else: 
    filename = request.POST.get('pdf_file_location') 
    if request.method == 'POST': 
     while os.path.exists(filename) is False: 
      time.sleep(2) 
     chunk_size = 8192 
     response = StreamingHttpResponse(FileWrapper(open(filename, 'rb'), chunk_size), 
             content_type=mimetypes.guess_type(filename)[0]) 
     response['Content-Length'] = os.path.getsize(filename) 
     response['Content-Disposition'] = "attachment; filename=%s" % filename[filename.find("UserSessionDetails-")+19:] 
     return response 
    return render(request, 'something/something/index.html') 

인 download.html

<canvas id="c-timer" width="300" height="300"> 
    <input id="pdf_file_location" type="hidden" value={{ pdf_file_location }} name="pdf_file_location"/> 
</canvas> 

JS는

var val = document.getElementById('pdf_file_location').value 
data ={"pdf_file_location": val}; 
something something and then finishTime is called 
var finishTime = function() { 
     $.post("/book_publish/download/",data); 
     }; 

어떻게 IDM 작품에 대한 많은 지식을 가지고 있지만하지 않습니다 독서 this article는 그것이 그것이 여러개의 공동 창을 열었다는 사실을 제외하고는 어떠한 우위도주지 말아야한다고 말한다. 작업에 대한 연결, 그리고 내 코드는 청크로 데이터를 전송합니다. 브라우저가 작은 덩어리로 전송 될 때 데이터를 꿰맬 수 없습니까?

답변

0

문제 : 문제점은 JS를 사용하여 다운로드 요청을 게시 한 것이었고 웹에서 초보자 였기 때문에 다시 요청을 처리 할 수 ​​없었습니다. 그러므로 모든 것이 엉망이되었습니다.

그리고 어떻게 든 IDM은 해당 응답을 받고 다운로드 프로세스를 시작할 수있었습니다.

해결

: 나는과 는 HTML 자체에 버튼 제출 및 사후 요청에 대한 JS를 사용하지 간단한 형태의 게시물을 사용했다.