Clyde Doris
Clyde Doris

Reputation: 1

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 browser 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

Upvotes: 0

Views: 647

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799520

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

Upvotes: 1

Related Questions