没有带可恢复上传的“Access

编程入门 行业动态 更新时间:2024-10-23 01:35:56
本文介绍了没有带可恢复上传的“Access-Control-Allow-Origin”标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

在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] cloud.google/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 www.googleapis/upload/storage/v1beta2/b/... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'ourapp.appspot' 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]cloud.google/storage/docs/json_api/v1/how-tos/upload#resumable

更多推荐

没有带可恢复上传的“Access

本文发布于:2023-11-26 17:58:09,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可恢复   上传   Access

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!