代码之家  ›  专栏  ›  技术社区  ›  Sergey Stolyarov

使用远程api将数据上载到BlobStore

  •  2
  • Sergey Stolyarov  · 技术社区  · 14 年前

    是否可以使用远程API(不是标准上载方案)将blob上载到blobstore?

    3 回复  |  直到 14 年前
        1
  •  1
  •   leoluk    14 年前


    远程api在最低级别工作 一旦你设置了 在存根上,你不用担心 在远程数据存储上:使用 注意,它的工作原理与 直接。( App Engine Help )

        3
  •  0
  •   Kwame    13 年前

    使用新的文件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