从GAE开始,GCS上传速度非常慢

时间:2014-10-06 10:14:45

标签: python google-app-engine

我在GAE上设置了一个简单的python项目,用户选择一个文件并上传到Google云端存储。这一切都很好,但是当我上传100kb文件时,上传时间为10-11秒。我怎样才能减少这个?

额外信息: 我的上传速度为100Mbis,结果与4kb图像相同,第一个帖子ID的延迟时间约为6秒enter image description here

import os
import urllib
import webapp2

    from google.appengine.ext import blobstore
    from google.appengine.ext.webapp import blobstore_handlers

    class MainHandler(webapp2.RequestHandler):
      def get(self):
        upload_url = blobstore.create_upload_url('/upload', gs_bucket_name='bucket_name')
        self.response.out.write('<html><body>')
        self.response.out.write('<form action="%s" method="POST" enctype="multipart/form-data">' % upload_url)
        self.response.out.write("""Upload File: <input type="file" name="file"><br> <input type="submit"
            name="submit" value="Submit"> </form></body></html>""")

    class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
      def post(self):
        upload_files = self.get_uploads('file')  # 'file' is file upload field in the form
        blob_info = upload_files[0]
        self.redirect('/serve/%s' % blob_info.key())

    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)

    app = webapp2.WSGIApplication([('/', MainHandler),
                                   ('/upload', UploadHandler),
                                   ('/serve/([^/]+)?', ServeHandler)],
                                  debug=True)

0 个答案:

没有答案