从Amazon S3的Retreive数据 [英] Retreive data from amazon s3

查看:187
本文介绍了从Amazon S3的Retreive数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图中检索来自Amazon S3的图片的URL。

这是我第一次这样做,所以请谁能帮助得到这个工作。

当我运行下面的脚本,我得到一个错误:缺少PARAMS所需的关键

这是我到目前为止有:

code:

 < HTML的xmlns =htt​​p://www.w3.org/1999/xhtml>
 < HEAD>


&所述;脚本的src =htt​​ps://sdk.amazonaws.com/js/aws-sdk-2.0.16.min.js>&所述; /脚本>


<脚本类型=文/ JavaScript的>

功能测试1(){

AWS.config.update({
accessKeyId:ACCESSKEY,
secretAccessKey:SecretKey的
});


AWS.config.region ='美西2';


VAR myAWS =新AWS.S3();

myAWS.getObject(

{斗:productissues,关键的:carlos.jpg},

功能(错误数据){
如果(错误!= NULL){
    警报(无法检索对象:+误差);
} 其他 {
    警报(装+ data.ContentLength +字节);
    //做些事情data.body
}

});

}

< / SCRIPT>

< /头>
 <身体GT;

 <按钮式=按钮的onclick =测试1(); >点击我<!/按钮>
 < /身体GT;
 < / HTML>
 

解决方案

请通过这个网址与正确的参数,第一次配置你的SDK。

http://docs.aws.amazon.com/AWSJavaScriptSDK/导游/浏览器configuring.html

你的code这部分导致了错误

  AWS.config.update({
accessKeyId:ACCESSKEY,
secretAccessKey:SecretKey的
});
 

您需要给他们默认为ACCESSKEY和SecretKey的你accessKeyId和secretAccessKey代替。他们应改为按照上面的URL所需的值。

此外,在的getObject PARAMS加上'键',而不是'关键'。

i am trying to retreive the url of a picture from Amazon s3.

this is the first time i am doing this, so please can anyone help to get this working.

when I run the script below, i get an error: ' Missing required Key in params'

This is what I have so far:

code:

<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>

解决方案

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.

这篇关于从Amazon S3的Retreive数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆