小编Oli*_*sin的帖子

允许使用 Amazon S3 的 OPTIONS HTTP 方法

我正在 HTML5 CORS 文件上传器上使用 Amazon S3。它运行良好,但我仍然发生了一件非常奇怪的事情。

在发送文件的PUT请求之前,浏览器总是发送一个OPTIONS请求,该请求会失败并返回403 FORBIDDEN错误代码。

但文件已正确传输到 S3,那么发生了什么?

我尝试通过启用所有 HTTP 方法来解决我的问题,但没有成功。

以下是我用于PUT请求的标头:

AWSAccessKeyId:XXXXXXXXXXXXXXXXXXXXXX
Expires:1347882643
Signature:YYYYYYYYYYYYYYYYYYYYY
Run Code Online (Sandbox Code Playgroud)

还有一些代码:

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);
Run Code Online (Sandbox Code Playgroud)

javascript amazon-s3

5
推荐指数
1
解决办法
5618
查看次数

标签 统计

amazon-s3 ×1

javascript ×1