javascript - 从 AWS S3 存储桶下载文件时如何避免出现 "Networking Error: Network Failure"?

标签 javascript amazon-s3

我正在使用 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>

最佳答案

我能够通过 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>

关于javascript - 从 AWS S3 存储桶下载文件时如何避免出现 "Networking Error: Network Failure"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21939010/

相关文章:

javascript - NodeJS MySQL : Query when second parameter is null

java - 无法在从 Web 应用程序发送的 Android 应用程序中下载媒体文件

amazon-web-services - 如何从存储桶根重定向到 AWS S3 中的子目录?

javascript - jQuery 动态居中未按预期工作

amazon-web-services - 针对经过身份验证的用户的 AWS S3 策略

hadoop - 亚马逊 EMR 和 Hive : Getting a "java.io.IOException: Not a file" exception when loading subdirectories to an external table

amazon-s3 - Python boto3 从 s3 加载模型 tar 文件并解压

javascript - 日期持续时间/日期减法计算

Javascript:原型(prototype)提供了无限调用对象方法的接口(interface)

javascript - 光标不会移动到 Electron 中的辅助显示