我正在尝试将位于Blobstore的文件从GAE发布到另一个HTTP服务(virustotal)。在
当前代码段适用于小文件(1-2 mb):
import base64
import json
import logging
from poster.encode import multipart_encode, MultipartParam
from google.appengine.api import urlfetch
def post_file(url, file_name, file_type, file_size, file_obj, options=dict(), username=None, password=None):
# Input checks
if url is None:
raise ValueError('url')
if file_name is None:
raise ValueError('file_name')
if file_type is None:
raise ValueError('file_type')
if file_size is None:
raise ValueError('file_size')
if file_obj is None:
raise ValueError('file_obj')
if options is None:
raise ValueError('options')
logging.debug('Preparing file {0}'.format(file_name))
# This is the post arguments section
options['file'] = MultipartParam('file', filename=file_name, filetype=file_type, filesize=file_size, fileobj=file_obj)
data, headers = multipart_encode(options)
logging.debug('Submitting the file to {0}'.format(url))
# For authorization (optional)
if username is not None and password is not None:
headers['Authorization'] = generate_authorization_header(username, password)
fetch = urlfetch.fetch(url=url, payload="".join(data), method=urlfetch.POST, headers=headers)
response = fetch.content
result = json.loads(response)
return result
当我对大文件(18 mb)使用此代码段时,出现以下异常:
^{pr2}$谢谢!在
应用引擎的urlphetch服务limits the request size to 10 megabytes。如果你有一个付费应用程序,你可以使用sockets(我建议使用httplib来简化代码,但要确保configure httplib to use sockets instead of urlfetch)。在
相关问题 更多 >
编程相关推荐