How to get s3 url in Nodejs?

120

Question: How to get s3 url in Nodejs?

I uploaded a file on s3. Now I want to get the s3 url node.js error of that file in Nodejs. The url should have format "s3://Bucket-name/filename.txt"

i tried s3.getSignedUrl() but it returned a https url.

Total Answers: 1

25

Answers 1: of How to get s3 url in Nodejs?

You can use the s3.upload method just like this

var params = {Bucket: 'bucket', Key: 'key', Body: stream}; var options = {partSize: 10 * 1024 * 1024, queueSize: 1}; s3.upload(params, options, function(err, data) {   console.log(err, data); }); 

once you do that you can fetch the URL of the uploaded file by

`data.Location` 

Aws Docs for data.Location ( check callback parameters )