相关疑难解决方法(0)

通过签名网址将文件PUT到Google云端存储(GCS)

我正在尝试使用"已签名的网址"来访问/上传文件到Google云端存储(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请求.

但是,我仍然得到这个(状态: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>
Run Code Online (Sandbox Code Playgroud)

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

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

我错过了什么?任何帮助将不胜感激.

java google-cloud-storage

12
推荐指数
2
解决办法
6226
查看次数

尝试从GAE python应用程序将文件写入GCS时出现ForbiddenError

我有这个代码:

def save_to_gcs(self, img, img_obj):
    '''
    Image data, Image metadata object -> Blob Key
    Given an image and image metadata, stores it in a GCS bucket
    '''
    bucket = '/foo'
    filename = bucket + '/' + str(img_obj['filename'])

    self.tmp_filenames_to_clean_up = []

    logging.info('Creating file %s\n' % img_obj['filename'])

    write_retry_params = gcs.RetryParams(backoff_factor=1.1)
    gcs_file = gcs.open(filename,
                        'w',
                        content_type=img_obj['mimetype'],
                        retry_params=write_retry_params)
    gcs_file.write(img)
    gcs_file.close()
    self.tmp_filenames_to_clean_up.append(filename)

    return blobstore.create_gs_key('/gs/' + filename)
Run Code Online (Sandbox Code Playgroud)

但它失败了这个错误:

Expect status [201] from Google Storage. But got status 403. Response headers: {'content-length': '145', 'via': 'HTTP/1.1 GWA', 'x-google-cache-control': …
Run Code Online (Sandbox Code Playgroud)

python google-app-engine google-cloud-storage

2
推荐指数
2
解决办法
1603
查看次数