AngularJS发送POST的OPTIONS请求,而不是 [英] AngularJS Sends OPTIONS request instead of POST
问题描述
我想上传图片到我的S3存储。我使用AngularJS v1.2.13。
当我使用的显示在他们的文档简单的情况下,一切工作正常(与动作
标签提交表单)。不过,如果我想这样做与 NG-点击角的方式
角发送选项
的要求,而不是 POST
的要求。
I'm trying to upload a picture to my S3 bucket. I'm using AngularJS v1.2.13.
When I use the simple case as displayed in their docs (submit form with action
tag) everything works fine. However, if I want to do it the Angular way with ng-click
Angular sends an OPTIONS
request instead of a POST
request.
以下是服务code,它首先进入的服务器,以获得一个签名(我知道,部分是罚款),然后尝试开机自检的一切。
The following is the Service code, it first goes to the server to get a signature (I know that part is fine) then tries to POST with everything.
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;
});
我是什么做错了吗?
What am I doing wrong?
推荐答案
我不知道这些资源会帮助你,但它听起来像同样的问题:
I don't know if these resources will help you, but it sounds like the same problem:
<一个href="http://stackoverflow.com/questions/20671619/angularjs-options-$p$pflight-call-$p$pceding-a-http-post-request">OPTIONS preflight调用preceding
这篇关于AngularJS发送POST的OPTIONS请求,而不是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!