尝试执行Blob存储并将表单数据添加到数据存储预检错误

时间:2022-08-06 23:11:37

Using Google Appengine Endpoints Created A servlet to help handle form post data for registration and uploading of a logo image file. The way it works is that it first of all goes to a blob servlet which will then return a link like this

使用Google Appengine端点创建一个servlet,用于帮助处理表单发布数据,以便注册和上载徽标图像文件。它的工作方式是首先进入一个blob servlet,然后返回一个像这样的链接

url: http://localhost:8080/_ah/upload/ag1oZXJjdWxlcy0yMDE1ciILEhVfX0Jsb2JVcGxvYWRTZXNzaW9uX18YgICAgICAqAkM

网址:http:// localhost:8080 / _ah / upload / ag1oZXJjdWxlcy0yMDE1ciILEhVfX0Jsb2JVcGxvYWRTZXNzaW9uX18YgICAgICAqAkM

for my form post to redirect to the url generated by the blob servlet, The JUNIT test is working well, But when i try to accept from my frontend built with angular i get the first response from the blob servlet which our URL now processing our form post to that url returns this error

对于我的表单帖子重定向到blob servlet生成的url,JUNIT测试运行良好,但是当我尝试接受我使用angular构建的前端时,我得到了来自blob servlet的第一个响应,我们的URL现在处理我们的表单发布到该url会返回此错误

XMLHttpRequest cannot load http://localhost:8080/_ah/upload/ag1oZXJjdWxlcy0yMDE1ciILEhVfX0Jsb2JVcGxvYWRTZXNzaW9uX18YgICAgICAqAkM.<br> 
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' <br>    header is present on the requested resource.    <br>    Origin 'http://localhost:9000' is therefore not allowed access.

been battling with this for days , what seems to be the problem with preflight

几天来一直在与这场斗争,这似乎是预检的问题

See the front end (from localhost:9000) code

请参阅前端(来自localhost:9000)代码

//send link to blob_store 
  /**
  blob_servlet_url is the link to our blob_servlet which is something like this localhost:8080/blob_servlet
  */
$http.get(blob_servlet_url)
  .success(function (data, status, headers, config) {
     //move our form data to server now
    uploadUrl=data; //return the url to forward form data
    console.log("Url:- "+data);
     var formData = {};

    $http({url:uploadUrl,method:'POST',data:formData}).then(
      function (resp) {
      //success
        console.log(resp);
    },
      function (reason) {
      //error 
      });


  })
  .error(function (data, status, header, config) {

  });

1 个解决方案

#1


0  

setting the content-type to undefined would make javascript pass the header data As it is , and over writing the default angular $httpProvider header configurations. Angular $http Documentation

将content-type设置为undefined将使javascript传递头文件数据,并且编写默认的角度$ httpProvider头配置。 Angular $ http文档

$http({url:url,method:"POST", headers:{'Content-Type':undefined}).then(success,failure); Theophiluses answer is correct 

#1


0  

setting the content-type to undefined would make javascript pass the header data As it is , and over writing the default angular $httpProvider header configurations. Angular $http Documentation

将content-type设置为undefined将使javascript传递头文件数据,并且编写默认的角度$ httpProvider头配置。 Angular $ http文档

$http({url:url,method:"POST", headers:{'Content-Type':undefined}).then(success,failure); Theophiluses answer is correct