1

I am trying to download a file from S3 directly in browser. I am using AWS Javascript SDK alongwith NodeJS + Webpack.

I am able to make a GetObject request and can see the browser (Chrome) downloading the bytes in "Developer tools" view.

I have "Content Disposition " header in response set as:

Content-Disposition:attachment; filename="A1.jpeg" 

However I do not see "Save As" dialog or any file being created in my filesystem (in Downloads folder). Where are the bytes going to?

How can I save the data in a file ?

Here's my code :

var getObject = function getObject(bucketName, fileName) { var params = { Bucket: bucketName, Key: fileName, ResponseContentDisposition: 'attachment; filename="' + fileName + '"' }; return s3.getObject(params).promise(); } getObject(BUCKET_NAME, item) .then( function (getFileResponse) { console.log(" file downloaded.. " ); } , function(error) { // Common error handling console.log(" error = " + error); }) 
2
  • Can you post your GetObject request? Commented Jun 14, 2017 at 15:47
  • @Nickel : Updated the question with my code.. Commented Jun 14, 2017 at 16:46

1 Answer 1

2

I faced this case before, then i used "s3.getSignedUrl" function instead of "s3.getObject" as following:

s3.getSignedUrl('putObject',s3Params).then(function(url){ //the returned "url" used by the browser to download },function(error){ //Error handling }) 

and the s3Params will contain (Buckey,key "object name" and so on)

Sign up to request clarification or add additional context in comments.

4 Comments

This sounds interesting.. My files will be huge (in GBs). What happens in the case when user starts the download - is Signed URL necessary only to initiate the download or for the whole period the download continues ?
Also can that URL be sniffed via developer tools ? If so other users, who are not authorized, can also download the file..
Related to the authorization issues, in my case authorization is required only during generating the url but there are another custom authorization on the user who can generate that url.
And what you need to care about related to the signed url is set the "Expires" parameter to make it available during the download process. I hope that help you ..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.