GSUTIL已将Url PUT签名到Google Cloud Storage失败

玛比希

我希望站点的用户能够在google cloud storage不使用Web应用程序服务器资源的情况下将文件上传到其中,因此签名的URL似乎是一种解决方法。

当用户选择要上传的文件时,jquery会将GET请求发送django签名的URL。网址是使用gsutil signurl命令生成的Django然后将签名的URL返回到模板,并在提交时jquery PUT发送带有签名的URL请求。

然而:

  • PUT请求失败,并显示“ SignatureDoesNotMatch”。
  • 使用此方法,对存储对象的GET请求可以正常工作。

是否有必须与PUT请求一起发送的必需标头?

gsutil命令(假设用户选择了文件“ map.html”)...

gsutil signurl -p notasecret -m PUT -d 10m /path/to/.p12 gs://bucket_name/map.html

jQuery PUT代码...

    $.ajax( {
  url: g_url,
  type: 'PUT',
  crossDomain: true,
  success: console.log('success'),
  error: function(XMLHttpRequest, textStatus, errorThrown){
    alert('status:' + XMLHttpRequest.status + ', status text: ' + XMLHttpRequest.statusText);
},
  data: file,
} );

g_url看起来像...

https://storage.googleapis.com/bucket_name/map.html?GoogleAccessId=__retracted__&Expires=1408889274&Signature=rDJAZQG4MIyMupy0M8HJ17r8rkEJcAbYSWpcq084SdzRh%2BnZavTfuWl4Q%2F6ytkSkN2c2%2B4b4pPRF5eWOEOL1InRxlB5pEBedPFZPpgDrRvR9tFybtH%2BkesKLhIZ3WjJ0utzAwhl%2BgAlQY6ulvO0Djib20zcG5fkHOigpRf1xBUk%3D
玛比希

原来我的问题与CORS有关。为了使它继续工作Django 1.6,我必须执行以下操作:

这样PUTDELETE请求开始工作。我遇到的唯一其他问题是不兼容的内容标题。因此,在发送请求之前,您需要在签名的url中设置内容类型。

gsutil命令看起来像

gsutil signurl -p notasecret -m PUT -d 10m -c 'multipart/formdata; charset=UTF-8' /path/to/.p12 gs://bucket_name/map.html

添加beforeSend到jquery请求

beforeSend: function (request){
request.setRequestHeader("Content-Type", 'multipart/formdata; charset=UTF-8')
;},

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Google Cloud Storage上的gsutil zip目录

在Google Cloud Storage签名的URL中提供回调URL

使用签名URL时Google Cloud Services失败

本地单元测试Google Cloud Storage签名的URL

如何使用Elixir或Erlang创建Google Cloud Storage签名URL?

使用PHP使用JWT为Google Cloud Storage签名URL

如何记录谁在 Google Cloud Storage 中下载了签名 URL?

HttpURLConnection PUT到Google Cloud Storage并显示错误403

从Google Cloud Function生成Cloud Storage签名URL,而无需使用显式密钥文件

Google Cloud Storage Transfer Service失败,出现UNKNOWN错误

Google Cloud Storage文件写入流失败

结算失败后无法重新激活Google Cloud Storage

在Google Cloud Storage中使用带有签名URL的版本控制

如何在GKE(Go)中为Google Cloud Storage对象生成签名的URL

如何使用 GOOGLE_APPLICATION_CREDENTIALS 环境变量对 Cloud Storage URL 进行签名?

如何使用项目级服务帐户为Google Cloud Storage创建签名的URL?

通过签名的URL上传到Google Cloud Storage-对象不公开

使用Python将文件上传到Google Cloud Storage签名的URL

无法签署Google Cloud Storage的URL

如何使用 gsutil 将文件从 Google Cloud Storage 存储桶 1 复制到存储桶 2,同时保留 ACL

从python后端到Google Cloud Storage中文件的公共URL(Google App Engine)

使用签名的URL上传到Google Cloud

使用URLPrefix的Google Cloud CDN签名URL

Jclouds分段上传到Google Cloud Storage失败,出现400错误请求

gsutil rsync是否对Google Cloud Storage Coldline存储桶产生额外费用

使用“gsutil”从 Cloud Storage 存储分区上传到 Google Colab 时出错

通过签名网址将文件放入Google Cloud Storage(GCS)

Cloud Storage Transfer作业失败,并显示“ Object:or”

Google Cloud Storage与Google Cloud CDN