我正在尝试将图片上传到我的 S3 存储桶。我正在使用 AngularJS v1.2.13。
当我使用他们的文档中显示的简单案例时(使用以下命令提交表单)action
标签)一切正常。但是,如果我想用 Angular 的方式来做ng-click
Angular 发送一个OPTIONS
请求而不是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;
});
我究竟做错了什么?
Angular 正在发送预检请求,因此如果您可以返回到您的第一个计划,请执行此操作!
https://stackoverflow.com/a/44343635/1308736 https://stackoverflow.com/a/44343635/1308736
https://stackoverflow.com/a/22968724/1308736 https://stackoverflow.com/a/22968724/1308736
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)