ge\x1cfO\xc1\x11ry\x0b\xea\xd1\x82\xf2\xa9-H..."). I can convert it to numpy array by doing this

问题描述 投票:0回答:1
, but I don't know what to do next to save video to file in mp4 format. Can you please help me?

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:

python flask post http-post
1个回答
1
投票

或者你可以使用一个名为 "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

© www.soinside.com 2019 - 2024. All rights reserved.