Function to create in-memory zip file and return as http response

前端 未结 2 998
醉话见心
醉话见心 2020-12-06 07:39

I am avoiding the creation of files on disk, this is what I have got so far:

def get_zip(request):
    import zipfile, StringIO
    i = open(\'picture.jpg\',         


        
相关标签:
2条回答
  • 2020-12-06 07:55

    For StringIO you should generally use o.getvalue() to get the result. Also, if you want to add a normal file to the zip file, you can use zf.write('picture.jpg'). You don't need to manually read it.

    0 讨论(0)
  • 2020-12-06 08:21

    Avoiding disk files can slow your server to a crawl, but it will certainly work.

    You'll exhaust memory if you serve too many of these requests concurrently.

    0 讨论(0)
提交回复
热议问题