Python 2.7 如何使用python 2.7将图像上传到google云存储
我遵循以下指南: 它只指定了如何上传文本文件,但我想上传图片。 我从前端获取了以下图像数据: const contentType='image/png'; const b64toBlob=b64Data,contentType=,sliceSize=512=>{ 常量ByTechCharacters=ATOBB64数据; 常量字节数组=[]; 对于let offset=0;offsetPython 2.7 如何使用python 2.7将图像上传到google云存储,python-2.7,google-app-engine,Python 2.7,Google App Engine,我遵循以下指南: 它只指定了如何上传文本文件,但我想上传图片。 我从前端获取了以下图像数据: const contentType='image/png'; const b64toBlob=b64Data,contentType=,sliceSize=512=>{ 常量ByTechCharacters=ATOBB64数据; 常量字节数组=[]; 对于let offset=0;offset
您可以尝试将图像作为blob上传,如中所示,以下代码适用于您:
def upload_blob(bucket_name, source_file_name, destination_blob_name):
"""Uploads a file to the bucket."""
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
blob.upload_from_filename(source_file_name)
print('File {} uploaded to {}.'.format(
source_file_name,
destination_blob_name))
您只需提供bucket名称、源文件名称以及将写入bucket的文件名。这就是我如何解决这一问题的方法,我花了3周时间在谷歌上痛苦地搜索 复制并粘贴下面的函数不要忘记ContentType,您可以将其设置为jpeg或其他格式。 无论如何,这个函数将base64数据转换为blob,我将其命名为image blob const contentType='image/png'; const b64toBlob=b64Data,contentType=,sliceSize=512=>{ 常量ByTechCharacters=ATOBB64数据; 常量字节数组=[]; 对于let offset=0;offset
data:data,//这对我不起作用,因为我不能这样做:从google.cloud导入存储。对它的支持显然已被放弃,我找到了另一种方法,感谢您分享对您有效的解决方法!