我正在使用HTML5 CORS文件上传器上的Amazon S3。它运作良好,但我仍然有一件很奇怪的事情正在发生。允许在Amazon S3上使用OPTIONS HTTP方法
之前PUT请求发送文件时,浏览器总是发送OPTIONS要求,从而未能与403 FORBIDDEN错误代码。
但该文件被正确传输到S3所以发生了什么?
请注意,我试图让所有的HTTP方法来解决我的问题,但它没有工作..
这里的头,我使用了PUT请求:
AWSAccessKeyId:XXXXXXXXXXXXXXXXXXXXXX
Expires:1347882643
Signature:YYYYYYYYYYYYYYYYYYYYY
还有一些代码的东西:
var xhr = new XMLHttpRequest();
// bind the event listener
xhr.upload.addEventListener("progress", progress_listener, false);
// open the XMLHttpRequest
xhr.open('PUT', signed_url, true);
// when the upload is completed call the callback function if supplied
xhr.onload = function(e) {
if(typeof callback == "function") {
callback(this.status == 200, file.name, file_id);
confirm_upload_success(file_id);
}
};
// start sending
xhr.send(file);
感谢您的帮助
您是否正确设置了CORS? http://docs.amazonwebservices.com/AmazonS3/latest/dev/cors。html – Evert
当然,但Amazon S3不允许您将OPTIONS放入允许的HTTP方法中 –