AppEngineのPython StandardEnvironmentからCloudStorageを使用します。DataStoreからCloudStorageに移行することで、保存データのバイト単価を1/10にすることができます。
CloudStorageを使用するには、appengine-gcs-clientをダウンロードして、アプリケーションのlibフォルダにcloudstorageフォルダをコピーします。
CloudStorageはバケットというフォルダのようなものに書き込みを行います。書き込み先のバケットをget_default_gcs_bucket_nameで取得することで、開発サーバでもCloudStorageは使用可能です。本番環境ではCloudStorageにあるアプリ名と同じ名称のデフォルトバケットに書き込まれます。
参考:Google App EngineからGoogle Cloud Storageを利用する
CloudStorageを使用するには、appengine-gcs-clientをダウンロードして、アプリケーションのlibフォルダにcloudstorageフォルダをコピーします。
CloudStorageはバケットというフォルダのようなものに書き込みを行います。書き込み先のバケットをget_default_gcs_bucket_nameで取得することで、開発サーバでもCloudStorageは使用可能です。本番環境ではCloudStorageにあるアプリ名と同じ名称のデフォルトバケットに書き込まれます。
from google.appengine.api import app_identity if 'lib' not in sys.path: sys.path[0:0] = ['lib'] import cloudstorage as gcs class ChunkManager(db.Model): def gcs_get_bucket_name(self): bucket_name = os.environ.get('BUCKET_NAME', app_identity.get_default_gcs_bucket_name()) return "/"+bucket_name+"/" def gcs_upload(self, filename, data): write_retry_params = gcs.RetryParams(backoff_factor=1.1) gcs_file = gcs.open(self.gcs_get_bucket_name()+filename, 'w', content_type='application/octet-stream', retry_params=write_retry_params) gcs_file.write(data) gcs_file.close() def gcs_contents(self, filename): gcs_file = gcs.open(self.gcs_get_bucket_name()+filename) contents = gcs_file.read() gcs_file.close() return contents def gcs_download(self, filename, out): contents = self.gcs_contents(filename) out.write(contents) def gcs_delete(self, filename): try: gcs.delete(self.gcs_get_bucket_name()+filename) except gcs.NotFoundError: pass
参考:Google App EngineからGoogle Cloud Storageを利用する