Google App Engine:上传前加密Blob

时间:2015-05-04 20:03:18

标签: python google-app-engine blobstore

我尝试在将其上传到Google App Engine Blobstore之前加密blob。

这是处理程序

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

1 个答案:

答案 0 :(得分:-1)

您似乎对blobstore上传的工作原理有误解。目前,您似乎正在将文件上传到应用引擎中的MyUploadHandler处理程序,然后将其上传到您从create_upload_url获取的URL的blobstore。

这不是它的工作方式。您应该将从create_upload_url 返回的URL返回给客户端。然后,客户端应该将文件上载到该URL。

如果要加密文件,则需要在最后一步中在客户端进行加密。