我有一个场景,我必须将文件从烧瓶应用程序上传到第三方 API。我已将所有 API 请求包装在 Flask 中以控制 API 使用。为此,我已将流量从主路由重定向到具有 http 307 状态的 api 包装器路由,以保留请求正文,并在 API 包装器中使用请求发布到第三方 API 端点。
问题是只有小于 100KB 的文件通过重定向请求发送,大于 100KB 的文件会在发送阶段以某种方式终止。
307 重定向和有效负载大小是否有任何限制?
我尝试通过观察网络计时堆栈跟踪进行调试,从那里看来,请求在发送阶段被丢弃了。
主要蓝图
@main.route('/upload/',methods=['POST','GET'])
def upload():
#for ajax call
if request.method == 'POST'
return redirect(url_for('api.file_push'),code=307)
else:
return render_template('file-upload.html')
API 蓝图
@api.route('/upload/',methods=['POST'])
def file_push():
upload_file = request.files['file']
filename = urllib.parse.quote(upload_file.filename)
toUpload = upload_file.read()
result=requests.post(apiInterfaces.FILE_UPLOAD_INTERFACE+'/'+filename,files{'file':toUpload})
return result
是的,我可以直接从主路由向 API 端点发送 post 请求,但我不想这样做,它会破坏我的系统设计和架构。