我使用AWS S3访问
HTML5应用程序中的文件.以下代码在我的笔记本电脑上工作正常,但在移动设备(iphone)上失败.任何帮助是极大的赞赏.
AWS.config.region = 'us-west-2'; var bucket = new AWS.S3({params: {Bucket: 'mybucket'}}); bucket.getObject({Key: myfile},function (error,data) { if (error != null) { alert("Failed to retrieve " + myfile + " :" + error); } else { //alert("Loaded " + data.ContentLength + " bytes"); localStorage[myfile] = data.Body.toString(); // do something with data.body }});
我得到的错误是:
“http //本地主机
无法检索foo.json:NetworkingError:网络故障“
我有这个桶的以下CORS配置
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <CORSRule> <AllowedOrigin>*</AllowedOrigin> <AllowedMethod>GET</AllowedMethod> <MaxAgeSeconds>3000</MaxAgeSeconds> </CORSRule>
解决方法@H_301_14@
我能够通过aws技术支持解决这个问题.使用以下CORSconfig解决了问题:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
<?xml version="1.0" encoding="UTF-8"?> <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <CORSRule> <AllowedOrigin>*</AllowedOrigin> <AllowedMethod>PUT</AllowedMethod> <AllowedMethod>POST</AllowedMethod> <AllowedMethod>GET</AllowedMethod> <MaxAgeSeconds>3000</MaxAgeSeconds> <AllowedHeader>*</AllowedHeader> </CORSRule> </CORSConfiguration>