by @kodeazy

How to access private s3 files using URI

Home » javascript » How to access private s3 files using URI

To access S3 bucket provide access configuration using AWS.config() method

region: "us-east-2",
signatureVersion: 'v4',
credentials: new AWS.Credentials(AccessKey, AccesSecreteKey, token)

Intitialize s3 variable using new AWS.S3()

var s3 = new AWS.S3();

To get access URI of the file we use getSignedUrl() method of s3 bucket Here we have three parameters

  • Bucket:Name of the Bucket
  • Key: Path inside the Bucket
  • Expires: No of seconds the required to enable the URI(maximum 1 week)
var presignedURI = s3.getSignedUrl('getObject', {
   Bucket: "Bucket_Name",
   Key: "FIle_Path",
   Expires: seconds

Here presignedURI variable provides the URL,we can access the file using this URL