Open RoccoFortuna opened 1 year ago
My minimal reproducible snippet:
bn = "my_bucket_name"
async def generate_download_signed_url_v4(
blob_name: str, expiration: int = 600
):
"""Generates a v4 signed URL for downloading a blob.
blob_name (str): the name of the file in the gcs bucket,
expiration (int): the number of seconds before the link expires
"""
async with gcloud.aio.storage.Storage() as client:
bucket = client.get_bucket(bucket_name=bn)
blob = await bucket.get_blob(blob_name=blob_name)
return await blob.get_signed_url(
expiration=expiration, # 600s = 10 minutes
)
if __name__ == "__main__":
import os
os.environ[
"GOOGLE_APPLICATION_CREDENTIALS"
] = "./path_to_credentials.json"
# check credentials are read fine
with open(os.environ["GOOGLE_APPLICATION_CREDENTIALS"]) as f:
print(f.read())
asyncio.run(generate_download_signed_url_v4(blob_name="1.jpg"))
@RoccoFortuna did you find a solution to this or is this still broken?
I'm trying to get signed urls for files in my bucket and it all works fine with the official library: https://cloud.google.com/storage/docs/samples/storage-generate-signed-url-v4#storage_generate_signed_url_v4-python
When I use gcloud.aio.storage's
.get_signed_url()
it throws a 403:Although the credentials used are the same and obviously the resource exists. Am I doing something wrong or is this function broken?