gpt4 book ai didi

python - 使用 get_serving_url 调整 GAE 中直接从 GCS 提供的图像大小?

转载 作者:太空宇宙 更新时间:2023-11-03 18:35:28 25 4
gpt4 key购买 nike

在我切换到 GCS 之前,我曾经能够使用动态调整图像大小功能 (=s200)。这对于存储在 GCS 上的图像可能吗?我似乎无法让它工作。

我将图像上传到 GCS,保存 blobkey,然后使用 get_serving_url 获取图像 url。使用该 URL,图像会显示在我的网站上。但如果我附加动态调整大小功能 (=s200),则会收到 404 错误。

这是我在 Flask 中使用的代码:

def gcs_upload_image (image, filename):

write_retry_params = gcs.RetryParams(backoff_factor=1.1)

with gcs.open(filename,
mode='w',
content_type=image.mimetype,
options={'x-goog-meta-foo': 'foo',
'x-goog-meta-bar': 'bar'},
retry_params=write_retry_params) as imageFile:
image.save(imageFile)

blobstore_filename = '/gs' + filename
return blobstore.create_gs_key(blobstore_filename)
<小时/>
@mod.route("/account", methods=["GET", "POST"])
@login_required
def account():
if request.method == "GET":
return render_template('users/account.html')
else:
image = request.files.get('file', None)
bucket = current_app.config['BUCKET']
filename = "/".join(['', bucket, g.user.key.id()])
if image:
if g.user.avatar:
blobstore.delete(g.user.avatar)

gcs_key = gcs_upload_image(image, filename)
blobkey = blobstore.BlobKey(gcs_key)
g.user.avatar = blobkey
g.user.put()
return redirect(url_for("users.account"))
<小时/>
@mod.route('/u/<userid>')
def profile(userid):
user = User.get_by_id(userid)
url = get_serving_url(user.avatar)
return render_template('users/profile.html', user=user, url=url)

最佳答案

您可以在调用 get_serving_url() 时使用大小和裁剪参数来动态调整图像大小。

关于python - 使用 get_serving_url 调整 GAE 中直接从 GCS 提供的图像大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21664041/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com