1

I have a problems saving video files on server using flask. Here is my client code( I am using react and super agent):

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

And server method

@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})

This code uploads and saves file on server, but after uploading this file become corrupted, and i can't play it this any video player.

I will be grateful for any help or advice

vallentin
  • 23,478
  • 6
  • 59
  • 81
  • After uploading a file, have you checked the file on the server to see how it was "corrupted"? Was it truncated (many Web servers have a configurable limit on the side of uploaded files)? It may also be possible that the file was uploaded properly, but won't appear to play properly because the type of the video file doesn't match the extension you are forcing (.mp4) when it's written. – payne Mar 04 '17 at 14:43
  • @payne , hello! Thanks a lot for your advice. I have found that this problem is appearing only when I was triyng to debug it in visual studio. Everything started working properly, when I deleted breakpoint from the the flask controller. – Oleg Shepotkin Mar 05 '17 at 09:12

0 Answers0