我正在研究如何将Pillow Image实例上载到Firebase存储桶。这个是可能的吗?
下面是一些代码:
from PIL import Image
image = Image.open(file)
# how to upload to a firebase storage bucket?我知道有一个gcloud-python库,但是它支持Image实例吗?将图像转换为字符串是我唯一的选择吗?
发布于 2017-01-30 16:28:12
gcloud-python库是要使用的正确库。它支持从字符串、文件指针和文件系统上的本地文件上传(请参阅医生们)。
from PIL import Image
from google.cloud import storage
client = storage.Client()
bucket = client.get_bucket('bucket-id-here')
blob = bucket.blob('image.png')
# use pillow to open and transform the file
image = Image.open(file)
# perform transforms
image.save(outfile)
of = open(outfile, 'rb')
blob.upload_from_file(of)
# or... (no need to use pillow if you're not transforming)
blob.upload_from_filename(filename=outfile)发布于 2022-04-04 14:39:19
这就是如何将枕头图像直接上传到火炉存储中。
from PIL import Image
from firebase_admin import credentials, initialize_app, storage
# Init firebase with your credentials
cred = credentials.Certificate("YOUR DOWNLOADED CREDENTIALS FILE (JSON)")
initialize_app(cred, {'storageBucket': 'YOUR FIREBASE STORAGE PATH (without gs://)'})
bucket = storage.bucket()
blob = bucket.blob('image.jpg')
bs = io.BytesIO()
im = Image.open("test_image.jpg")
im.save(bs, "jpeg")
blob.upload_from_string(bs.getvalue(), content_type="image/jpeg")https://stackoverflow.com/questions/41932529
复制相似问题