我试过你们给我们举的例子,我想我找到了解决办法。
经过一些挖掘,我发现你可以
stream requests
requests
模块:
请求支持流式上载,这允许您发送大型流或文件,而无需将其读入内存。
您只需要提供一个要流式传输的文件,并以读取二进制模式打开它,
rb
.
app.py
from flask import Flask, request
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST', 'PUT'])
def hello_world():
# 'bw' is write binary mode
with open("BigBuckBunny_320x180_flask_upload.mp4", "bw") as f:
chunk_size = 4096
while True:
chunk = request.stream.read(chunk_size)
if len(chunk) == 0:
return 'Done'
f.write(chunk)
if __name__ == '__main__':
app.run()
上传器
import requests
# Give proper path to your file, I used mine from flask app directory
with open('BigBuckBunny_320x180.mp4', 'rb') as f:
requests.post('http://127.0.0.1:5000/', data=f)
this