How to write Big files into Blobstore using experimental API?

和自甴很熟 提交于 2019-11-30 02:13:02

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!