1
我在我的django網頁上有一個下載鏈接。 當我下載一個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
我使用Apache服務器。誰能告訴我解決方案?
奇怪...我有幾乎完全相同的代碼正在使用的生產,它的工作... – Nemeth