Reputation: 15064
I want to write a javascript code that downloads a certain file from S3 once click a button. Can you propose me something that can work?
Upvotes: 0
Views: 861
Reputation: 81
Downloading a file from S3 is done through the GetObject method of the SDK.
var params = {
Bucket: 'STRING_VALUE', /* required */
Key: 'STRING_VALUE', /* required */
IfMatch: 'STRING_VALUE',
IfModifiedSince: new Date || 'Wed Dec 31 1969 16:00:00 GMT-0800 (PST)' || 123456789,
IfNoneMatch: 'STRING_VALUE',
IfUnmodifiedSince: new Date || 'Wed Dec 31 1969 16:00:00 GMT-0800 (PST)' || 123456789,
Range: 'STRING_VALUE',
RequestPayer: 'requester',
ResponseCacheControl: 'STRING_VALUE',
ResponseContentDisposition: 'STRING_VALUE',
ResponseContentEncoding: 'STRING_VALUE',
ResponseContentLanguage: 'STRING_VALUE',
ResponseContentType: 'STRING_VALUE',
ResponseExpires: new Date || 'Wed Dec 31 1969 16:00:00 GMT-0800 (PST)' || 123456789,
SSECustomerAlgorithm: 'STRING_VALUE',
SSECustomerKey: new Buffer('...') || 'STRING_VALUE',
SSECustomerKeyMD5: 'STRING_VALUE',
VersionId: 'STRING_VALUE'
};
s3.getObject(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
More information about using the AWS SDK in javascript can be found here
Upvotes: 2