Upload ndarray(image in OpenCV) on to google cloud storage as a .jpg or .png

前端 未结 2 1984
傲寒
傲寒 2021-01-22 19:19

I have a similar issues like How to upload a bytes image on Google Cloud Storage from a Python script.

I tried this

from google.cloud import storage
imp         


        
2条回答
  •  后悔当初
    2021-01-22 20:11

    You are calling blob = bucket.get_blob(gcs_image) which makes no sense. get_blob() is supposed to get a string argument, namely the name of the blob you want to get. A name. But you pass a file object.

    I propose this code:

    with TemporaryFile() as gcs_image:
        image.tofile(gcs_image)
        gcs_image.seek(0)
        blob = bucket.blob('documentation-screenshots/operations/15.png')
        blob.upload_from_file(gcs_image)
    

提交回复
热议问题