Retrieve data from Amazon s3

别说谁变了你拦得住时间么 提交于 2020-03-04 08:01:52

问题


I am trying to retrieve the URL of a picture from Amazon s3.

When I run the script below, I get an error:

Missing required Key in params

This is what I have so far:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>


<script  src="https://sdk.amazonaws.com/js/aws-sdk-2.0.16.min.js"></script>


<script type="text/javascript">

function test1(){

AWS.config.update({
accessKeyId: 'accesskey',
secretAccessKey: 'secretKey'
});


AWS.config.region = 'us-west-2';


var myAWS = new AWS.S3();

myAWS.getObject(

{ Bucket: 'productissues', key: 'carlos.jpg' },

function (error, data) {
if (error != null) {
    alert("Failed to retrieve an object: " + error);
} else {
    alert("Loaded " + data.ContentLength + " bytes");
    // do something with data.body
}

});

}

</script>

</head>
 <body>

 <button type="button" onclick="test1();" >Click me!</button>
 </body>
 </html>

回答1:


Please go through this url for configuring your sdk first with proper parameters.

http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/browser-configuring.html

This part of your code is causing the error

AWS.config.update({
accessKeyId: 'accesskey',
secretAccessKey: 'secretKey'
});

You need to give your accessKeyId and secretAccessKey instead of defaulting them to accesskey and secretkey. They should be replaced with required values following the above url.

Also add 'Key' instead of 'key' in getObject params.



来源:https://stackoverflow.com/questions/25896259/retrieve-data-from-amazon-s3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!