はジャンゴ1.3を使用してブラウザからファイルをダウンロードしたコードであるとApache 2.2 mod_xsendfileとDjangoの添付ファイル全体をダウンロードすることができませんでし
@login_required
def sendfile(request, productid):
path = settings.RESOURCES_DIR
filepath = os.path.join('C:/workspace/y/src/y/media/audio/','sleep_away.mp3')
print "filepath",filepath
filename = 'sleep_away.mp3' # Select your file here.
print "Within sendfile size", os.path.getsize(filepath)
wrapper = FileWrapper(open(filepath,'r'))
content_type = mimetypes.guess_type(filename)[0]
response = HttpResponse(wrapper, content_type = content_type)
print "Within wrapper"
from django.utils.encoding import smart_str
response['X-Sendfile'] = smart_str(filepath)
response['Content-Length'] = os.path.getsize(filepath)
from django.utils.encoding import smart_str
response['Content-Disposition'] = 'attachment; filename=%s/' % smart_str(filename)
return response
コンソールはsendfileの中で適切なサイズ ある以下のファイルサイズを示していサイズ4842585
ファイルをダウンロード/保存すると、107 KB、つまり109,787バイトと表示されます。間違っています。なぜ完全なファイルをダウンロードしていないのですか?
うまく機能のおかげPannu ... ...私は次の行を編集していた:応答=のHttpResponse(file_wrapperに応答=のHttpResponseを(CONTENT_TYPE = file_mimetype、file_wrapper) 、content_type = file_mimetype)。 – Anjali
私はうれしいです:)しかし、 'content_type'を' ** kwargs'引数の後に置くのは本当に問題ありません。解決策があなたのために働いていれば、それが開かれたままではないように、答えとしてマークしてください。 :) – Pannu