0

I followed the url tutorial below in the stackoverflow itself, and I would like to know how I can also have the option to list the files of a Buckt and then how I can download these files, below my current code to UPLOAD, I would like to supplement to DOWNLOAD and LIST the bucket files

import asyncio
import aiohttp
from aiofile import AIOFile
from gcloud.aio.storage import Storage 


BUCKET_NAME = 'unscanned-malware-scann-lab'
FILE_NAME  = 'testeArquivoUp.txt'

async def async_upload_to_bucket(blob_name, file_obj, folder='uploads'):
    """ Upload csv files to bucket. """
    async with aiohttp.ClientSession() as session:
        storage = Storage(service_file='./creds.json', session=session) 
        status = await storage.upload(BUCKET_NAME, f'{folder}/{blob_name}', file_obj)

        return status['selfLink']
        
async def main():
    print('Começou a processar')
    async with AIOFile(FILE_NAME, mode='r') as afp:
        f = await afp.read()
        url = await async_upload_to_bucket(FILE_NAME, f)
        print(url)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())
  • 1
    Did you look at the `gcloud.aio` source code at all? The `Storage` class has methods for `download`, `delete`, and `list_objects` right alongside `upload`. – Tim Roberts Jul 05 '22 at 18:41
  • Hello, I already looked but I couldn't find an example to write my code, I already have the code to upload, read the files in the bucket and now I need to assemble one to download and delete the file from the bucket, maybe can you help me with these examples? – Rodrigo Augusto Martins Jul 07 '22 at 14:02
  • They're going to be comparable. I don't know of examples; you'll have to look at the code to see what parameters it expects. – Tim Roberts Jul 08 '22 at 05:43

0 Answers0