How to send a video via POST?

3

I have an application that is being written in Node.js and using Electron, I need to send a video in mp4 format via POST to the server. How can I do this?

EDIT 1:

In the application, I use FFmpeg to create a five minute video from the webcam. I need to send this video to the server using a POST request, what I want to know is if there is a way to send this file using this request. Be it directly, encoding it somehow, transforming into binary or otherwise whatever.

    
asked by anonymous 09.11.2017 / 19:48

1 answer

3

Use the request module to perform the operation, and createReadStream to read the local file in binary mode:

    const request = require("request");

    request({
            method: "POST",
            url: "http://www.servidor.com/upload",
            formData: { 
                       upload_type: "txt", 
                       file: fs.createReadStream("/folder/arquivo.txt") }
        },
        function(err, response, body) { console.log(err, response, body) });

Sources:

09.11.2017 / 20:14