How to write Big files into Blobstore using experimental API?

前端 未结 2 1706
礼貌的吻别
礼貌的吻别 2020-12-28 09:41

I have dilemma.. I\'m uploading files both in scribd store and blobstore using tipfy as framework. I have webform with action is not created by blobstore.create_upload_url (

相关标签:
2条回答
  • 2020-12-28 09:57

    finally i found solution.

    Nick Johneson's answer occurred attribute error because uploaded_file is treated as string. string didn't have read() method.

    Cause string doesn't have method read(), i spliced file string and write it just like he wrote.

    class UploadRankingHandler(webapp.RequestHandler):
      def post(self):
        fish_image_file = self.request.get('file')
    
        file_name = files.blobstore.create(mime_type='image/png', _blobinfo_uploaded_filename="testfilename.png")
    
        file_str_list = splitCount(fish_image_file,65520)
    
        with files.open(file_name, 'a') as f:
          for line in file_str_list:
            f.write(line)
    

    you can check about splitCount(). here

    http://www.bdhwan.com/entry/gaewritebigfile

    0 讨论(0)
  • 2020-12-28 10:05

    You need to make multiple, smaller calls to the file API, for instance like this:

    with files.open(file_name, 'a') as f:
        data = uploaded_file.read(65536)
        while data:
          f.write(data)
          data = uploaded_file.read(65536)
    

    Note that the payload size limit on regular requests to App Engine apps is 10MB; if you want to upload larger files, you'll need to use the regular blobstore upload mechanism.

    0 讨论(0)
提交回复
热议问题