将Blobstore迁移到GCS:Google App Engine Python

将Blobstore迁移到GCS:Google App Engine Python,第1张

概述这是我现有的用于将数据上传到blobstore的py代码.from google.appengine.api import files def save_data_to_blob_store(data): # Create the file file_name = files.blobstore.create(mime_type='appl

这是我现有的用于将数据上传到blobstore的py代码.

from @R_404_5561@.appengine.API import filesdef save_data_to_blob_store(data):    # Create the file    file_name = files.blobstore.create(mime_type='application/octet-stream')    # Open the file and write to it    with files.open(file_name,'a') as f:        f.write(data)    # Finalize the file. Do this before attempting to read it.    files.finalize(file_name)    # Get the file's blob key    blob_key = files.blobstore.get_blob_key(file_name)    return str(blob_key)

现在我正在尝试弃用blobstore&转移到GCS.我写了一些代码但没有按预期工作.

def save_data_to_gcs(request):    file_name = '/gs/bucket-name-1/new_file' # change bucket/object names to suit your needs    writable_file_name = files.gs.create(file_name,mime_type='application/octet-stream',acl='public-read')    with files.open(writable_file_name,'a') as f:        f.write('Hello World!\n')        f.write('This is a @R_404_5561@ Cloud Storage object!\n')    files.finalize(writable_file_name)

在执行此过程时,GAE在生产中抛出错误,

Exception in request:Traceback (most recent call last):  file "/base/data/home/apps/s~bfsolu/248.371810019093562707/common/zip-packages/django-1.1.zip/django/core/handlers/base.py",line 92,in get_response    response = callback(request,*callback_args,**callback_kwargs)  file "/base/data/home/apps/s~bfsolu/248.371810019093562707/myapp/utils.py",line 51,in save_data_to_gcs    acl='public-read')  file "/base/data/home/runtimes/python27/python27_lib/versions/1/@R_404_5561@/appengine/API/files/gs.py",line 326,in create    return files._create(_GS_fileSYstem,filename=filename,params=params)  file "/base/data/home/runtimes/python27/python27_lib/versions/1/@R_404_5561@/appengine/API/files/file.py",line 647,in _create    _make_call('Create',request,response)  file "/base/data/home/runtimes/python27/python27_lib/versions/1/@R_404_5561@/appengine/API/files/file.py",line 252,in _make_call    _raise_app_error(e)  file "/base/data/home/runtimes/python27/python27_lib/versions/1/@R_404_5561@/appengine/API/files/file.py",line 210,in _raise_app_error    raise PermissionDenIEdError(e) PermissionDenIEdError: ApplicationError: 8

任何人都可以帮助在save_data_to_gcs程序中纠正我,不胜感激.

谢谢.

最佳答案GCS需要activate your project.

然后授予您的应用程序在Google Cloud Console使用您的存储桶的权限:

为此,请选择您的存储桶,单击“存储桶权限”按钮,然后添加新的“用户”权限,提供您的应用程序电子邮件地址(app-id@appspot.gserviceaccount.com)并将其设为所有者.

总结

以上是内存溢出为你收集整理的将Blobstore迁移到GCS:Google App Engine Python全部内容,希望文章能够帮你解决将Blobstore迁移到GCS:Google App Engine Python所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1205287.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存