In AWS S3 bucket is mainly used to store files.
To access S3 bucket files follow below steps.
Provide access configuration using AWS.config() method as below.
AWS.config.update({
region: "us-east-2",
signatureVersion: 'v4',
credentials: new AWS.Credentials(AccessKey, AccesSecreteKey, token)
});
Later 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
});
console.log(presignedURI);
Here presignedURI variable provides the URL,we can access the file using this URL
Top comments (0)