How to access private s3 files using URI in javascript?
Jul 21, 2022
To access S3 bucket provide access configuration using AWS.config() method
AWS.config.update({
region: "us-east-2",
signatureVersion: 'v4',
credentials: new AWS.Credentials(AccessKey, AccesSecreteKey, token)
});Intitialize s3 variable using new AWS.S3()
Get G vamsi venkatesh’s stories in your inbox
Join Medium for free to get updates from this writer.
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
});
console.log(presignedURI);Here presignedURI variable provides the URL,we can access the file using this URL




