无法为 Google 云存储签署 URL
Unable to sign URLs for Google Cloud Storage
我尝试了多种方式来签署云存储 URL。继续获取:
对预检请求的响应未通过访问控制检查:请求的资源上不存在 'Access-Control-Allow-Origin' header。因此不允许访问来源“#####”。
kod 应该可以工作,因为我已经测试了多个库:
from google.cloud import storage
storage_client = storage.Client()
bucket = storage_client.get_bucket(app_identity.get_default_gcs_bucket_name())
latest_blob = None
for blob in bucket.list_blobs():
bn = blob.name
if not latest_blob or bn > latest_blob.name:
latest_blob = blob
signed_url = latest_blob.generate_signed_url(
int(time.time()) + 3600,
method='GET',
content_type="text/csv")
self.redirect(signed_url)
我认为可能需要一些 Cloud-console-settings 魔法。
我已通过 IAM 和存储桶授予服务帐户对存储的完全访问权限。
我认为重定向可能是问题所在,但 copy-paste 也不起作用;签名不匹配。
听起来你有两个问题:
听起来您正试图在网络浏览器中使用 JavaScript 中的 URL。如果是这样,您需要在 objects 上设置 CORS 策略,因为默认设置是拒绝 cross-origin 请求。查看 https://cloud.google.com/storage/docs/cross-origin 了解详情。
除此之外,当您直接输入 URL 时,听起来您的请求也失败了,并且您收到了 SignatureDoesNotMatch 异常。我猜问题是您为 GET 请求指定了 content_type 。客户端在发出请求时不指定 "Content-Type" header。尝试删除它。
我尝试了多种方式来签署云存储 URL。继续获取:
对预检请求的响应未通过访问控制检查:请求的资源上不存在 'Access-Control-Allow-Origin' header。因此不允许访问来源“#####”。
kod 应该可以工作,因为我已经测试了多个库:
from google.cloud import storage
storage_client = storage.Client()
bucket = storage_client.get_bucket(app_identity.get_default_gcs_bucket_name())
latest_blob = None
for blob in bucket.list_blobs():
bn = blob.name
if not latest_blob or bn > latest_blob.name:
latest_blob = blob
signed_url = latest_blob.generate_signed_url(
int(time.time()) + 3600,
method='GET',
content_type="text/csv")
self.redirect(signed_url)
我认为可能需要一些 Cloud-console-settings 魔法。
我已通过 IAM 和存储桶授予服务帐户对存储的完全访问权限。 我认为重定向可能是问题所在,但 copy-paste 也不起作用;签名不匹配。
听起来你有两个问题:
听起来您正试图在网络浏览器中使用 JavaScript 中的 URL。如果是这样,您需要在 objects 上设置 CORS 策略,因为默认设置是拒绝 cross-origin 请求。查看 https://cloud.google.com/storage/docs/cross-origin 了解详情。
除此之外,当您直接输入 URL 时,听起来您的请求也失败了,并且您收到了 SignatureDoesNotMatch 异常。我猜问题是您为 GET 请求指定了 content_type 。客户端在发出请求时不指定 "Content-Type" header。尝试删除它。