vos*_*usa 7 python google-app-engine python-2.7 google-cloud-storage
下面的应用引擎代码使用app_identity.sign_blob()来请求已签名的网址.当GCS文件名中没有空格时,此代码可以正常工作.对象名称中允许有空格.为了测试,我使用了SDK.
我已经看到很多关于这个问题的问题,但我无法创建解决方案
这是一个bug还是?
def sign_url(bucket_object, expires_after_seconds=6, bucket=default_bucket):
    method = 'GET'
    gcs_filename = urllib.quote('/%s/%s' % (bucket, bucket_object))
    content_md5, content_type = None, None
    # expiration : number of seconds since epoch
    expiration_dt = datetime.utcnow() +    timedelta(seconds=expires_after_seconds)
    expiration = int(time.mktime(expiration_dt.timetuple()))
    # Generate the string to sign.
    signature_string = '\n'.join([
        method,
        content_md5 or '',
        content_type or '',
        str(expiration),
        gcs_filename])
    signature_bytes = app_identity.sign_blob(signature_string)[1]
    # Set the right query parameters. we use a gae service account for the id
    query_params = {'GoogleAccessId': google_access_id,
                    'Expires': str(expiration),
                    'Signature': base64.b64encode(signature_bytes)}
    # Return the built URL.
    result = '{endpoint}{resource}? {querystring}'.format(endpoint=GCS_API_ACCESS_ENDPOINT,
                                                          resource=gcs_filename,    
                                                          querystring=urllib.urlencode(query_params))
return result
更新.我使用签名网址时的响应:
<Error>
    <Code>NoSuchKey</Code>
    <Message>The specified key does not exist.</Message>
</Error>
问题已经解决了。
我不知道为什么。我没有改变任何东西。您可以使用下面的代码和此链接尝试 GAE 应用程序:
https://voscausa-gae.appspot.com/download_signed?bucket_object=download/test signed1 .txt
代码在这里:appengine-gcs-signed-url
您还可以使用带有策略文档的签名 URL 来直接上传到 GCS。
代码: https: //github.com/voscausa/appengine-gcs-upload