25 Mayıs 2009, PAZARTESİ
Üreten Django ile indirmek için dosya
Bir zıp arşivi ve indirmek için sunuyor, ama yine de sabit diskine bir dosya kaydetmek mümkün mü?
CEVAP
26 Mayıs 2009, Salı
Content-Disposition
başlık ayarlamanız gerekir bir yükleme tetiklemek için:
from django.http import HttpResponse
from django.core.servers.basehttp import FileWrapper
# generate the file
response = HttpResponse(FileWrapper(myfile.getvalue()), content_type='application/zip')
response['Content-Disposition'] = 'attachment; filename=myfile.zip'
return response
Eğer diskteki dosya istemesen bile StringIO
kullanmak gerekir
import cStringIO as StringIO
myfile = StringIO.StringIO()
while not_finished:
# generate chunk
myfile.write(chunk)
Content-Length
başlık olarak ayarlayabilirsiniz isteğe bağlı olarak:
response['Content-Length'] = myfile.tell()
Bunu Paylaş:
Sunucu üzerinden indirmek için değil, ...
Nasıl indirmek ve internetten bir dosy...
Javascript/JSON veri ile posta yoluyla...
Openssl uzantısı https üzerinden dosya...
C bir URL bir dosya indirmek için nası...