我试图将图片上传到我的S3存储桶。我正在使用AngularJS v1.2.13。 当我使用他们的文档中显示的简单案例(使用action
标签提交表单)时,一切正常。但是,如果我想要这样做,那么Angular将发送OPTIONS
请求,而不是请求POST
。AngularJS发送OPTIONS请求而不是POST
以下是服务代码,它首先去服务器获取签名(我知道该部分是好的),然后尝试POST所有内容。
myServices.factory('s3', function($http) {
var service = {};
service.upload = function(fileName) {
return $http(
{
method:"POST",
url: "sign",
data: { "fileName": fileName }
}
).then(
function(result) {
// success
//resolve the promise as the data
var data = result.data;
var url = "https://" + data.bucket + ".s3.amazonaws.com/";
return $http.post(url, {
"key": data.key,
"AWSAccessKeyId": data.awsKey,
"acl": data.acl,
"policy": data.policy,
"signature": data.signature,
"Content-Type": "image/jpeg",
"success_action_redirect": "http://localhost:3000/s3Uploaded"
}).then(
function(response) {
// success
console.log("s3.upload, success: ");
console.log(response);
},
function(response) {
// failed
console.log("s3.Upload, fail: ");
console.log(response);
}
);
},
function(response) {
// failed
console.log("s3.sign, fail: ");
console.log(response);
}
);
};
return service;
});
我在做什么错?