我想通过python脚本在Google Cloud Storage上上传图像。这是我的代码:
from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient import discovery
scopes = ['https://www.googleapis.com/auth/devstorage.full_control']
credentials = ServiceAccountCredentials.from_json_keyfile_name('serviceAccount.json', scop
es)
service = discovery.build('storage','v1',credentials = credentials)
body = {'name':'my_image.jpg'}
req = service.objects().insert(
bucket='my_bucket', body=body,
media_body=googleapiclient.http.MediaIoBaseUpload(
gcs_image, 'application/octet-stream'))
resp = req.execute()
Run Code Online (Sandbox Code Playgroud)
如果gcs_image = open('img.jpg', 'r')代码有效并且可以将我的映像正确保存在Cloud Storage中。如何直接上传字节图像?(例如,从一个的OpenCV / numpy的数组:gcs_image = cv2.imread('img.jpg'))
我正试图找出一种使用Google App Engine将图像上传到Google云端存储的方法.
我检查过:
使用Google App Engine将图像/视频上传到Google云存储
他们都展示了如何使用BlobStore API来完成它.
当我检查BlobStore API时:https://cloud.google.com/appengine/docs/python/blobstore/
他们提供了使用Google云端存储的说明.BlobStore的当前状态是什么,未来是否会得到支持?
我看到了图像上传的示例:https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/appengine/standard/blobstore/main.py使用BlobStore API.
是否有使用Google App Engine的Google云端存储示例?