我正在构建一个应用程序引擎端点 api,它从用户(android 应用程序)获取照片并以编程方式将其保存到 blobstore。然后我将 blob_key 保存在我的数据存储中。代码如下:
然后我像这样保存到 blobstore:
from google.appengine.api import files
def save_image(data):
# Create the file
file_name = files.blobstore.create(mime_type='image/png')
# 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 # which is then saved to datastore
现在我想恢复图像。我不知道如何将以下代码放入我的端点 api 中:
from google.appengine.ext import blobstore
from google.appengine.ext.webapp import blobstore_handlers
class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self, resource):
resource = str(urllib.unquote(resource))
blob_info = blobstore.BlobInfo.get(resource)
self.send_blob(blob_info)
最后我想象一个这样的服务过程:
我的做法是因为我想保护用户的隐私。关于如何做好这件事有什么想法吗?我的代码片段一般来自google开发者教程.
EDIT:
我不知道如何将 blob_key 从数据存储传递到以下方法来检索图像:
from google.appengine.ext import blobstore
from google.appengine.ext.webapp import blobstore_handlers
class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self, resource):
resource = str(urllib.unquote(resource))
blob_info = blobstore.BlobInfo.get(resource)
self.send_blob(blob_info)
里面有什么resource
, 反正?