【发布时间】:2017-12-27 12:34:35
【问题描述】:
我想使用 google.appengine.api 图像包,但我不知道如何安装 virtualenv 工具。当我在正常环境中使用 dev_appserver.py 时,该程序包工作正常,但是当我将灵活环境与烧瓶一起使用时,它找不到该程序包。有没有办法将图像库添加到我的 virtualenv 中?
当我在将图像上传到服务器之前尝试使用 Pillow 调整图像大小时,但当我这样做时,图像会以 0B 的速度到达云存储。
if file and allowed_file(file.filename):
filename = '%s_%s.jpg' % (item.id, len(item.photos))
# Resize file using pillow
image = Image.open(file)
image.thumbnail((300,300)
resized_image = io.BytesIO()
image.save(resized_image, format='JPEG')
# if I did a image.show() here the image would
# properly be shown resized
gcs = storage.Client()
bucket = gcs.get_bucket(CLOUD_STORAGE_BUCKET)
blob = bucket.blob(filename)
blob.upload_from_file(resized_image,
content_type=file.content_type)
# I would then view the image in the bucket and it shows up as 0 bytes
# and blank
# If I just use the regular file it uploads fine.
【问题讨论】:
-
你能检查
resized_image是否包含你所期望的吗? -
可能是
blob.upload_from_file(resized_image.get_value(),...? -
尝试使用真实文件而不是
io.BytesIO。如果可行,那显然是io.BytesIO匹配问题,这是我怀疑的。我无法测试自己,因为我既没有使用 flex env 也没有使用烧瓶...... -
如果您使用
f的句柄呼叫blob.upload_from_file()?
标签: python google-app-engine google-cloud-platform virtualenv pillow