我有一个类似的问题,例如How to upload a bytes image on Google Cloud Storage from a Python script。
我试过这个
from google.cloud import storage
import cv2
from tempfile import TemporaryFile
import google.auth
credentials, project = google.auth.default()
client = storage.Client()
# https://console.cloud.google.com/storage/browser/[bucket-id]/
bucket = client.get_bucket('document')
# Then do other things...
image=cv2.imread('/Users/santhoshdc/Documents/Realtest/15.jpg')
with TemporaryFile() as gcs_image:
image.tofile(gcs_image)
blob = bucket.get_blob(gcs_image)
print(blob.download_as_string())
blob.upload_from_string('New contents!')
blob2 = bucket.blob('document/operations/15.png')
blob2.upload_from_filename(filename='gcs_image')
Run Code Online (Sandbox Code Playgroud)
这是构成的错误
> Traceback (most recent call last): File
> "/Users/santhoshdc/Documents/ImageShapeSize/imageGcloudStorageUpload.py",
> line 13, in <module>
> blob = …Run Code Online (Sandbox Code Playgroud)