使用远程API将数据上传到BlobStore

2 投票
3 回答
1014 浏览
提问于 2025-04-16 03:04

有没有办法通过远程API把blob上传到blobstore,而不是用标准的上传方式?

我想为我的应用写一个备份和恢复的脚本,但blobstore是唯一不工作的部分。

3 个回答

0

有一个更好的解决方案,使用新的文件API:http://code.google.com/appengine/docs/python/blobstore/overview.html

这个方法对我来说效果很好。下面是一些示例代码:

from __future__ import with_statement
from google.appengine.api import files
from google.appengine.ext import blobstore

def get_blob_key(self, data, _type):
    # Create the file
    file_name = files.blobstore.create(mime_type = _type)

    # 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 blob_key
1

我曾经解决过一个关于如何通过程序上传到blobstore的问题,并在我的博客上写了一篇简短的教程/说明。希望对你有帮助:http://swizec.com/blog/programatically-uploading-to-blobstore-in-python/swizec/1423

1

三天前,Blobstore的远程API访问功能被添加进来了:


远程API在数据存储的最底层工作,所以一旦你设置好了相关的工具,你就不用担心自己是在操作一个远程的数据存储。只要注意一些小细节,它的工作方式和你直接访问数据存储是完全一样的。(App Engine帮助文档)

撰写回答