6

I want to get the link of the file (or file name is also fine) after I uploaded my image to S3. I upload using below code and it worked.

s3Bucket.putObject(data, function(err, data){
        if (err) { 
          console.log(err);
          res.send({result:0});
        } else {
          res.send({result:1});
          console.log(data)
        }
    });

But in the callback data it has only 1 property, the etag. In the doc it clearly stated it has other object, so how do I get the path of the uploaded file?

1 Answer 1

5

The docs don't imply that the object key will be available in the data callback parameter.

You can work out the S3 URI of the created object based on the bucket's name and the params.Key property on the request data.

Here's an example of how to do that from within the putObject callback

s3Bucket.putObject(data, function(err, data) {
  var params = this.request.params;
  var region = this.request.httpRequest.region;
  console.log('s3://' + params.Bucket + '/' + params.Key);
  console.log('https://s3-' + region + '.amazonaws.com/' + params.Bucket + '/' + params.Key)
});
Sign up to request clarification or add additional context in comments.

1 Comment

this url will always be so? there will be some way to get the url (NOT signed) from the sdk?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.