通过签名网址将文件PUT到Google云端存储(GCS) [英] PUT files to Google Cloud Storage (GCS) via Signed URLs

查看:201
本文介绍了通过签名网址将文件PUT到Google云端存储(GCS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用已签名的网址访问/上传文件到Google云端存储(GCS)。

I am trying to use "signed URLs" to access/upload files to Google Cloud Storage (GCS).

按照 https://developers.google.com/storage/docs/accesscontrol#Signing-Strings

我做了什么:


  • 在Google Cloud Console注册了Web应用程序。

  • 使用已注册的Web应用程序屏幕的证书部分中的生成新密钥生成新的私钥。

  • 创建要签名的字符串并对其进行签名使用页面如何签名部分提供的示例代码(只需对Java主程序的硬编码值进行微调)。更新:为 GcsSigner.java 创建了一个要点。

  • 确保签名字符串是URL编码。

  • 指定的HTTP标头:x-goog-api-version,x-goog-project-id,Content-Type。

  • 指定的网址参数:GoogleAccessId,签名,过期。

  • 使用Postman(Chrome扩展程序)模拟PUT请求。

  • Registered a "Web Application" at Google Cloud Console.
  • Generated new private key using the "Generate New Key" at the "Certificate" section of the registered web application screen.
  • Created my string to be signed and sign it using the sample code provided by "How to Sign" section of the page (just minor tweaks to hardcode values for the Java main program). Update: Created a gist for GcsSigner.java.
  • Ensure that the signed string is URL encoded.
  • HTTP headers specified: x-goog-api-version, x-goog-project-id, Content-Type.
  • URL Parameters specified: GoogleAccessId, Signature, Expires.
  • Use Postman (a Chrome extension) to simulate PUT request.

但是,我仍然得到这个(状态:403 Forbidden):

However, I am still getting this (Status: 403 Forbidden):

<?xml version='1.0' encoding='UTF-8'?>
<Error>
    <Code>SignatureDoesNotMatch</Code>
    <Message>The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.</Message>
    <StringToSign>PUT

text/plain
1384084959392
x-goog-api-version:2
x-goog-project-id:99999
/mybucket/myfile.txt</StringToSign>
</Error>

即使我根据StringToSign中的值对字符串进行重试,我仍然会得到相同的结果错误。

Even when I retry by signing the string based on values in "StringToSign", I still get the same error.

在此阅读各种相关帖子,但找不到任何解决方案,其中大部分都是指 x-goog-api-version:1 当我使用的是版本2.

Read various related postings here but could not find any solution and most of it refers to x-goog-api-version:1 while i am using version 2.

我缺少什么?任何帮助将不胜感激。

What am i missing? Any help would be greatly appreciated.

推荐答案

最后使用签名网址将PUT文件设置为Google云端存储。这是通过创建一个简单的Java程序来模拟:

Finally managed to PUT files to Google Cloud Storage using signed URLs. This was done by creating a simple Java program to simulate:


  • 服务器签署&安培;将字符串编码为签名。

  • Uploader 作为未经身份验证的用户仅使用服务器。使用Apache的HTTP客户端库模拟浏览器。

  • Server to sign & encode a string as signature.
  • Uploader as an unauthenticated user submitting the PUT request using only the signature provided by Server. Browser is simulated using Apache's HTTP Client library.

您可以看到演示应用这里。

我真的不明白为什么当我通过Chrome提交时它不起作用邮递员延期。

I do not really understand why it did not work when I submitted through Chrome's Postman extension.

这篇关于通过签名网址将文件PUT到Google云端存储(GCS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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