bw4sz
bw4sz

Reputation: 2257

Upload python object to Google Cloud Storage without saving it to file

I am clipping images in Python 2.7 on Windows 10 and would like to send them to Google's Cloud Vision API. For images saved locally, I can send them using the google.cloud python module like this:

                blob.upload_from_filename(filename=path)                        

Documented here

I would rather not save each crop to file, just to send the numpy arrays directly. I could change the numpy arrays to str objects and use

blob.upload_from_string()

but then Cloud Vision API would not be able to read them in my bucket. Is there any way to pipe from python to cloud storage bucket without wasting time/space saving them as an intermediate temporary object?

Upvotes: 4

Views: 1403

Answers (2)

umang garg
umang garg

Reputation: 51

you can convert your numpy array to json and then

filename = "file_name_required on cloud"
json_object = [] # your array

and then do

blob = BUCKET.blob(filename)
blob.upload_from_string(data=json.dumps(json_object),content_type='application/json')

Upvotes: 1

James
James

Reputation: 1962

Unfortunately there is not. I am sorry!

Upvotes: 2

Related Questions