3

I'm using gcloud.aio.storage (with the fake-gcs-server emulator) and I've succesfully uploaded blobs to an existing bucket.

import os
import pytest
# Set ENV before Storage import, otherwise it gets set to prod gcs endpoint
os.environ["STORAGE_EMULATOR_HOST"] = "localhost:4443"
from gcloud.aio.storage import Storage

### WORKS OK #####
@pytest.mark.asyncio
async def test_upload_blob_to_existing_bucket() -> None:

    async with Storage() as async_client:
        existing_bucket_name: str = "fake_server_bucket"
        await async_client.upload(existing_bucket_name, "myBlobName.json", 
"blobContent")
pytest test_gcs_async_upload.py
======= 1 passed in 0.24s ======

How can I upload blobs to a new bucket ??

The below always returns me: aiohttp.client_exceptions.ClientResponseError: 404, message='Not Found...' on the bucket

I looked at the test cases in the gcloud.aio.storage library itself, but they do not seem to do anything different from what I'm attemptying.

It's also missing the method to create_bucket(bucket) beforehand (like I could do in the synch google.cloud.storage library).

import os
import pytest
# Set ENV before Storage import, otherwise it gets set to prod gcs endpoint
os.environ["STORAGE_EMULATOR_HOST"] = "localhost:4443"
from gcloud.aio.storage import Storage

### Returns 404 notfound error ###
@pytest.mark.asyncio
async def test_upload_blob_to_new_bucket() -> None:

    async with Storage() as async_client:
        # async_client.create_bucket(bucket) #Cannot do this in gcloud.aio.storage lib!
        new_bucket_name: str = "newbucket"
        await async_client.upload(new_bucket_name, "myBlobName.json", "blobContent")
pytest test_gcs_async_upload.py

E   aiohttp.client_exceptions.ClientResponseError: 404, message='Not Found: 
{"error":{"code":404,"message":"Not Found","errors":null}}\n', 
url=URL('http://localhost:4443/upload/storage/v1/b/newbucket/o? 
name=myBlobName.json&uploadType=media')
======= 1 failed in 0.20s ======

Thank you for the help :-)

SETUP:

python = ">=3.8,<3.11"
gcloud-aio-storage = "^7.0.1"
pytest = "^7.1.2"
pytest-asyncio = "^0.19.0"

fake-gcs-server is LATEST, TAG = 1 digest = 80e798b48cdd.
It runs as a docker instance and is prepopulated with a bucket and some blobs at startup  
AxA
  • 319
  • 5
  • 18

0 Answers0