I am running a Google cloud function, which accesses the google cloud storage bucket for an excel file. My goal is to read the file and do some calculations with it, but is it possible without downloading the file to the /tmp folder? Things I have tried:
storage_client = storage.Client()
file_obj = storage_client.get_bucket(‘bucketname’).get_blob('filename.xlsx')
excel_file = None
file_obj.download_to_file(excel_file)
wb = openpyxl.load_workbook(excel_file)
at first I thought I could attain a file object, but then after I read the error message I realised I was being asked for a file path so I would have to download to the /tmp folder, which is something I would like to avoid.
I also tried download_as_bytes()
, but unfortunately openpyxl cannot read bytes.
Any help/hint would be appreciated :)
openpyxl
expects a path or takes a file-like object, so if you have a bytes you can follow the example in that answer to your case. Do you think this will work for you case? – Rafael Lemos