How do I create a download link for a file present in amazon S3 using python boto?

How can I create a download link for a file present in amazon S3 using python boto? I tried (key.generate_url). But it opens the .txt file in the browser instead of downloading.

+3


source to share


1 answer


When creating the URL, you must specify the "content disposition" response header:

headers = {'response-content-disposition': 'attachment; filename="your-filename.txt"'}
url = key.generate_url(expires_in=600, response_headers=headers)

      



When a URL is used , this will cause S3 to return a Content-Disposition Header , which tells the browser that it should download the file rather than display it directly.

0


source







All Articles