我想在瀏覽器網頁的示例中使用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-2
或us-east-1
。當我去我的水桶的控制檯,URL是https://console.aws.amazon.com/s3/home?region=us-west-2
但有人在這裏提到美國標準是us-east-1
。
美國標準是'us-east-1' – slayedbylucifer
我試過了... – alexpja