【发布时间】:2015-05-04 20:03:17
【问题描述】:
我正在尝试在将 Blob 上传到 Google App Engine Blobstore 之前对其进行加密。
这里是处理程序
class MyUploadHandler(webapp2.RequestHandler):
def post(self):
upload_url = blobstore.create_upload_url('/myAfterUploadHandler')
inFile = self.request.POST.multi['file'].file
outFile = StringIO.StringIO()
encryptFile(inFile,outFile,DATAKEY)
datagen, headers = multipart_encode({"file": outFile})
request = urllib2.Request(upload_url, \
datagen, headers)
self.response = urllib2.urlopen(request)
我在 urllib2 尝试发布请求的最后一行遇到问题。
这里是长异常的最后一部分
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/urlfetch.py", line 270, in fetch
allow_truncated, follow_redirects, validate_certificate)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/urlfetch.py", line 326, in make_fetch_call
request.set_payload(payload)
File "cpp_message.pyx", line 124, in cpp_message.SetScalarAccessors.Setter (third_party/apphosting/python/protobuf/proto1/cpp_message.cc:2229)
TypeError: <type 'instance'> has type <type 'instance'>, but expected one of: str, unicode
【问题讨论】:
-
不是该特定问题的答案,但我建议您尽可能使用Python Client for Google Cloud Storage。
-
这是我的要点,展示了应用程序如何将 blob 发送到 blobstore。 gist.github.com/voscausa/9222732
-
@voscausa 谢谢!你认为GCS会更好吗?我真的在考虑 Jaime 的建议
-
是的,GCS 会好很多。文件 API 已被弃用。在这里你可以看到我如何使用 GCS 作为替代品:github.com/voscausa/appengine-gcs-blobstore-python 使用 GCS 你仍然可以使用 blobstore 下载和上传
标签: python google-app-engine blobstore