从App Engine文件API迁移 [英] Migrating from App Engine Files API

查看:87
本文介绍了从App Engine文件API迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序将一堆图像存储为斑点。这大概是我如何存储图像。

My app stores a bunch of images as blobs. This is roughly how I store images.

from google.appengine.api import files
# ...
fname = files.blobstore.create(mime_type='image/jpeg')
with files.open(fname, 'a') as f:
  f.write(image_byte)
files.finalize(fname)
blob_key = files.blobstore.get_blob_key(fname)

提供这些图片,我使用 images.get_serving_url(blob_key)

To serve these images, I use images.get_serving_url(blob_key).

以下是我的问题:


  1. 我必须将所有Blob复制到Google Cloud Storage吗?换句话说,我能够使用GCS客户端库和现有的blob密钥访问我的现有blob吗?或者,我是否必须将blob复制到GCS并获得新的blob密钥?

  2. 假设我必须将它们复制到GCS,最简单的方法是什么?有没有移植工具或什么?否则,是否有一些示例代码可以复制粘贴?

谢谢!

推荐答案

<1>不,你仍然可以使用blobstore。您也可以在使用BlobstoreUploadHandler时将文件上传到Blobstore。

1) No, you can still use the blobstore. You can also upload files to the blobstore when you use the BlobstoreUploadHandler.

2)当您使用blobstore时,迁移很容易,因为您可以为GCS对象创建一个blobkey。当您使用默认的GCS存储桶时,您可以免费使用配额。

2) Migration is easy when you use the blobstore, bacause you can create a blobkey for GCS objects. And when you use the default GCS bucket you have free quota.

from google.appengine.api import app_identity
import cloudstorage as gcs

default_bucket = app_identity.get_default_gcs_bucket_name() 
gcs_filename = '/%s/%s' % (default_bucket, image_file_name)
with gcs.open(gcs_filename, 'w', content_type='image/jpeg') as f:
    f.write(image_byte)

blob_key = blobstore.create_gs_key('/gs' + gcs_filename)
# and create a serving url

这篇关于从App Engine文件API迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆