print(request.files['video'].read())
np.frombuffer(request.files['video'].read(), np.uint8)
I am writing a Python backend for an Android app with Flask. I get video from POST method (when I do this: print(request.files['video'].read()) I get "d3\xb9}\xff\x04\xa4M\xef\x8fS\xc1\xf0\x9e:
或者你可以使用一个名为 "Flask-Uploads "的扩展,它可以让你以一种方便的方式处理文件上传。
这里是一个例子。关于Flask-Uploads的详细文档,请看这里。
https:/pythonhosted.orgFlask-Uploads
from flask_uploads import UploadSet
from werkzeug.utils import secure_filename
media = UploadSet('media', ('mp4')) # Create an upload set that only allow mp4 file
....
@app.route('/upload/', methods=["POST"])
def upload():
if "video" in request.files:
video = request.files["video"]
filename = secure_filename(file.filename) # Secure the filename to prevent some kinds of attack
media.save(video, name=filename)
# Video saved