tags:

views:

24

answers:

1
        wrapper = FileWrapper(file("C:/pics.zip"))
        content_type = mimetypes.guess_type(result.files)[0]
        response = HttpResponse(wrapper, content_type=content_type)
        response['Content-Length'] = os.path.getsize("C:/pics.zip")
        response['Content-Disposition'] = "attachment; filename=pics.zip"
        return response

pics.zip is a valid file with 3 pictures inside.

server response the download, but when I am going to open the zip, winrar says This archive is either in unknown format or damaged!

If I change the file path and the file name to a valid image C:/pic.jpg is downloaded damaged too.

What Im missing in this download view?

+1  A: 

The problem is that you're not reading it as a binary file :) This should work:

wrapper = FileWrapper(file("C:/pics.zip", 'rb'))
WoLpH