4

I have a my_folder.tar.gz archive with a structure

my_folder.tar.gz:
    my_folder/
        file1
        file2

And I construct a basic flask endpoint, say:

@blueprint.route('/download')
def download():
    return send_file('/path/to/my_folder.tar.gz',
                     as_attachment=True,
                     attachment_filename='my_name.tar.gz')

And when I run it the first time everything runs smoothly and the browser downloads the proper archive. The thing is when I run it the second time, inside the archive there's a file my-name.tar-1 and not the folder I was hoping to send. I try another time, the filename my-name.tar-2 etc etc.

It turns out that when I change the attachment_filename parameter to a new value, the download works again but also only once. The same situation happens with the send_from_directory() function.

That's a very bizarre behaviour. Does anybody have an idea what might be happening?

stpk
  • 2,015
  • 1
  • 16
  • 23
  • It sounds like your client is renaming the file. A lot of browsers do this when there is a name conflict. What happens if you delete the downloaded file before you download it a second time? – dirn Oct 11 '15 at 12:57
  • Hmmmm, actually when I download it on the hard drive everything is fine. The problem occurs only when I click `Open with` and not `Save file` in the browser dialog box. – stpk Oct 11 '15 at 13:10

1 Answers1

-1

you have to use,

return send_file('/path/to/my_folder.tar.gz',as_attachment=True, attachment_filename='my_name.tar.gz, cache_timeout=0')
hardik gosai
  • 328
  • 3
  • 17