没有带可恢复上传的“Access-Control-Allow-Origin”标头 [英] No 'Access-Control-Allow-Origin' header with resumable upload

查看:136
本文介绍了没有带可恢复上传的“Access-Control-Allow-Origin”标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在通过我们的App Engine应用程序中的云存储JSON API生成可恢复的上传url,这些应用程序在移动设备以及Web应用程序上使用。
在web应用程序中,使用XmlHttpRequest上传带有可恢复上传url的文件,我们得到以下错误:
$ b XMLHttpRequest无法加载 https://www.googleapis.com/upload/storage/v1beta2/b/ 。 ..没有'Access-Control-Allow-Origin'标题出现在请求的资源上。因此, https://ourapp.appspot.com 不允许访问。



在Chrome开发人员工具中,网络日志显示第一个OPTIONS请求,其中包含相应的Origin请求标头和Access-Control-Allow-Origin响应标头,但以下PUT请求失败,如上所述。



我们的桶上的cors xml如下所示:

 <?xml version =1.0encoding =UTF-8?> 
< CorsConfig>
< Cors>
< Origins>
< Origin> *< / Origin>
< / Origins>
<方法>
<方法> PUT< /方法>
<方法> GET< /方法>
<方法> POST< / Method>
<方法> HEAD< / Method>
<方法>删除< /方法>
<方法>选项< /方法>
< / Methods>
< ResponseHeaders>
< ResponseHeader> *< / ResponseHeader>
< / ResponseHeaders>
< MaxAgeSec> 1800< / MaxAgeSec>
< / Cors>
< / CorsConfig>

欢迎您提出任何建议。



谢谢。

解决方案

经过这个问题,发现这是由于在初始POST请求中丢失了origin App Engine。



我的POST请求包含content-length(设置为0),x-upload-content-type以及origin和all。



[1] https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload#resumable


We are generating resumable upload url through the cloud storage JSON API from our App Engine application which are used on mobile as well as a web app. In the web app, using XmlHttpRequest to upload a file with the resumable upload url we get the following error :

XMLHttpRequest cannot load https://www.googleapis.com/upload/storage/v1beta2/b/... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://ourapp.appspot.com' is therefore not allowed access.

In Chrome developer tools, the network log show a first OPTIONS request with the appropriate "Origin" request header and "Access-Control-Allow-Origin" response header but the following PUT request fails as mentioned.

The cors xml on our bucket looks like this:

<?xml version="1.0" encoding="UTF-8"?>
    <CorsConfig>
      <Cors>
        <Origins>
          <Origin>*</Origin>
        </Origins>
        <Methods>
          <Method>PUT</Method>
          <Method>GET</Method>
          <Method>POST</Method>
          <Method>HEAD</Method>
          <Method>DELETE</Method>
          <Method>OPTIONS</Method>
        </Methods>
        <ResponseHeaders>
          <ResponseHeader>*</ResponseHeader>
        </ResponseHeaders>
        <MaxAgeSec>1800</MaxAgeSec>
      </Cors>
    </CorsConfig>

Any suggestions are welcome.

Thanks.

解决方案

Ran into this problem and discovered that it was due to a missing "origin" header in the initial POST request coming from App Engine.

My POST request contains content-length (set to 0), x-upload-content-type, and origin and all is well.

[1]https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload#resumable

这篇关于没有带可恢复上传的“Access-Control-Allow-Origin”标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆