2014-03-18 74 views
3

我想在瀏覽器網頁的示例中使用AWS提供的示例,並且我一直收到NetworkingError: Network Failure錯誤。這裏是我使用的是什麼:AWS S3 JavaScript SDK - NetworkingError:網絡故障

<html> 
<head> 
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.0.0-rc11.min.js"></script> 
<script type="text/javascript"> 
    // See the Configuring section to configure credentials in the SDK 

    AWS.config.update({accessKeyId: '####', secretAccessKey: '####', region: 'us-east-1'}); 
    // Configure your region 
// AWS.config.region = ''; 
</script> 
</head> 
<body> 
<input type="file" id="file-chooser" /> 
<button id="upload-button">Upload to S3</button> 
<div id="results"></div> 

<script type="text/javascript"> 
    var bucket = new AWS.S3({params: {Bucket: 'BUCKETNAMEGOESHERE'}}); 

    var fileChooser = document.getElementById('file-chooser'); 
    var button = document.getElementById('upload-button'); 
    var results = document.getElementById('results'); 
    button.addEventListener('click', function() { 
    var file = fileChooser.files[0]; 
    if (file) { 
     results.innerHTML = ''; 

     var params = {Key: file.name, ContentType: file.type, Body: file}; 
     bucket.putObject(params, function (err, data) { 
     results.innerHTML = err ? err : 'UPLOADED.'; 
     }); 
    } else { 
     results.innerHTML = 'Nothing to upload.'; 
    } 
    }, false); 
</script> 

<div id="status"></div> 
<ul id="objects"></ul> 

<script type="text/javascript"> 
    var bucket = new AWS.S3({params: {Bucket: 'BUCKETNAMEGOESHERE'}}); 
    bucket.listObjects(function (err, data) { 
    if (err) { 
     document.getElementById('status').innerHTML = 
     'Could not load objects from S3'; 
    } else { 
     document.getElementById('status').innerHTML = 
     'Could not load objects from S3'; 
    } else { 
     document.getElementById('status').innerHTML = 
     'Loaded ' + data.Contents.length + ' items from S3'; 
     for (var i = 0; i < data.Contents.length; i++) { 
     document.getElementById('objects').innerHTML += 
      '<li>' + data.Contents[i].Key + '</li>'; 
     } 
    } 
    }); 
</script> 
</body> 
</html> 

我鬥是美國標準的區域,而且我麻煩搞清楚它是否使用us-west-2us-east-1。當我去我的水桶的控制檯,URL是https://console.aws.amazon.com/s3/home?region=us-west-2但有人在這裏提到美國標準是us-east-1

+0

美國標準是'us-east-1' – slayedbylucifer

+0

我試過了... – alexpja

回答

2

這真的很晚,但如果有人絆倒了這一點,您需要確保您的控制檯中的CORS文件具有足夠的權限。

+0

謝謝!修改CORS爲我工作! – VMTrooper

+0

@VMTrooper可以請你在這裏分享你的CROS。謝謝 – usama