无法使用烧瓶

时间:2017-03-04 13:25:00

标签: python flask superagent

我在使用flask保存服务器上的视频文件时遇到问题。 这是我的客户端代码(我正在使用react和super agent):

onDrop(files){
    var req = request.post('/upload');
    files.forEach((file)=> {
        req.attach('videoFile', file);
    });
    req.end(() => this.fileUploaded(files[0].name));
}

和服务器方法

@app.route('/upload', methods=["POST"])
def upload():
    try:
        fileName = '{0}{1}{2}'.format('zz', ''.join(random.sample(char_set, 8)),  '.mp4')
        path = os.path.join('web', app.config['UPLOAD_FOLDER'], fileName)
        url = '/video/{0}'.format(fileName)

        file = request.files['videoFile']

        if file:
            file.save(path)           
            return flask.jsonify({'success': True , 'fileName': url})
    except Exception as ex:
        return flask.jsonify({'success': False, 'message': ex})

此代码在服务器上传和保存文件,但上传后该文件已损坏,我无法播放任何视频播放器。

我将不胜感激任何帮助或建议

0 个答案:

没有答案
相关问题