In continuation to the post where I explained how to upload to Amazon S3 using Javascript , this post will focus on downloading the document from Amazon S3 using native JavaScript and Visualforce page.
Copy and paste the below JavaScript code in the VF page which would enable you to download the specified file. Change the text mentioned in Red
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.1.12.min.js"></script>
<script type="text/javascript">
AWS.config.update(
{
accessKeyId: "YOUR AWS ACCESS KEY ID",
secretAccessKey: "YOUR AWS SECRET ACCESS KEY",
region_config: "eu-west-1"
}
);
var s23 = new AWS.S3();
var y="Name of the file which is to be downloaded";
var params = {Bucket: 'BUCKET NAME', Key: y};
s23.getSignedUrl('getObject', params, function (err, url) {
window.open(url,"_self");
});
</script>
If you have any question don't hesitate to mention them in comments!!
Getting Error
ReplyDeleteThe specified key does not exist
even i have file.
That is really nice to hear. thank you for the update and good luck. main Image
ReplyDeleteNote that a file transfer administration saves your information in its web worker for a pre-chosen timeframe. file transfer
ReplyDelete