问题描述
我正在尝试从Amazon s3检索图片的URL.
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>
推荐答案
请首先通过此url使用适当的参数配置sdk.
Please go through this url for configuring your sdk first with proper parameters.
http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/browser-configuring.html
这部分代码导致错误
AWS.config.update({
accessKeyId: 'accesskey',
secretAccessKey: 'secretKey'
});
您需要提供accessKeyId和secretAccessKey,而不是将它们默认为accesskey和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.
还要在getObject参数中添加键"而不是键".
Also add 'Key' instead of 'key' in getObject params.
这篇关于从Amazon s3检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!