2011-07-29 7 views
1

장고에있는 내 웹 페이지 중 하나에 다운로드 링크가 있습니다. 75MB의 오디오 파일을 다운로드 할 때 오디오는 0 바이트 만 다운로드하지만 아무것도 다운로드하지 않습니다. 내가 아파치 서버를 사용django를 사용하여 다운로드하는 방법은 무엇입니까?

from django.core.servers.basehttp import FileWrapper 
import mimetypes 
rec_file = settings.WEB_PATH + "/media/recording/" + filename 
wrapper = FileWrapper(open(rec_file, "r")) 
contentType = mimetypes.guess_type(rec_file)[0] 
response = HttpResponse(wrapper, mimetype = "application/force-download") 
response['Content-Length'] = os.path.getsize(rec_file) 
response['Content-Disposition'] = "attachment; filename=" + filename 
return response 

:

이 내 코드입니다. 아무도 내게 솔루션을 말할 수 있습니까?

+0

이상한 ... 프로덕션에서 사용되는 거의 동일한 코드가 있고 작동합니다 ... – Nemeth

답변

2

코드에 어떤 문제가 있는지 말할 수는 없지만 어쨌든 그렇게하지 말아야합니다. Apache에서 정적 파일을 직접 제공하거나 X-Sendfile을 사용해야합니다.

+0

예, 지금은 아파치를 사용하고 있습니다. 난 그냥 내가 장고를 사용하여 그것을 할 수 있는지 알고 싶었어요. – northlondoner

관련 문제