How to get the URL of a file on AWS S3 using aws-sdk?

768
June 07, 2017, at 08:54 AM

I'm using a AWS Lambda function to create a file and save it to my bucket on S3, it is working fine. After executing the putObject method, I get a data object, but it only contains an Etag of the recently added object.

s3.putObject(params, function(err, data) {
    //data only contains Etag
});

I need to know the exact URL that I can use in a browser so the client can see the file. The folder has been already made public and I can see the file if I copy the Link from the S3 console.

I tried using getSignedUrl but the URL it returns is used for other purposes, I believe.

Thanks!

Answer 1

When you called PutObject, you provided the bucket and the object's key. You can simply combine those to make the URL of the object, for example:

  • http://s3.amazonaws.com/bucket/key (for path-style URL), or
  • http://bucket.s3.amazonaws.com/key (for virtual-hosted style URL)

So, for example, if your bucket is pablo and the object key is dogs/toto.png, use:

  • http://s3.amazonaws.com/pablo/dogs/toto.png (for path-style URL), or
  • http://pablo.s3.amazonaws.com/dogs/toto.png (for virtual-hosted style URL)

For region-specific buckets, see Working with Amazon S3 Buckets.

Rent Charter Buses Company
READ ALSO
Manage private node modules without a registry

Manage private node modules without a registry

I'm working on a project where some of my react components could be used in further projects of mineI don't necessarily want them to make public, but that is fine

323
JSON Route is returning Empty

JSON Route is returning Empty

I am trying to scrape some info from a website and return it in an APIThe object, RESULT, is being logged in the terminal, but when i go to /api/scrape, the JSON object is empty

419
RESTful service using express and typescript - this undefined for Response.send()

RESTful service using express and typescript - this undefined for Response.send()

Appears that "this" is undefined inside of a expressResponse

361
afnetworking can't send body to node.js server, how use?

afnetworking can't send body to node.js server, how use?

AFNetworking set the http body, but my nodejs server can't recv the body

298