开发者

django/python | Get files from database, zip, then send to browser

Please help me with my problem.

I'm sorry if this sounds noobie, coz I really am. There are files (jpg, docs) in a certain database, how would I select those file in the database, save them in a zip file, then send over to the browse开发者_如何学Gor as HttpResponse or something like this:

response = HttpResponse(mimetype='application/zip')
response['Content-Disposition'] = 'filename=group.zip'

The part which greatly bothers me is when taking the files from the database coz Google doesn't seem to be helpful at that.

Some of the relevant codes I have are these:

temp = request.POST.getlist('cbox') #cbox is the field in form
tempx = models.FileTable.objects.filter(pk__in = temp)

I no longer know what to do from here. Thanks in advance! :p


You're looking for zipfile and StringIO. Create a StringIO, open it as a ZipFile, add files to it, then send it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜