How to send a video via POST?

Asked

Viewed 115 times

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 that?

EDIT 1:

In the app, I use Ffmpeg to create a five-minute webcam video. 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, coding it somehow, turning it into binary or otherwise.

  • Send a video via POST? explain this better

  • I edited the question trying to explain better.

  • You will not send the video, you will upload the video and in case (if you want) to save in the bank, you will take the name and extension and save. That’s it

1 answer

3


Use the module request to carry out 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:

  • It helped me a lot, what I need now is to add an entire parameter to the request body. "testeId": "01234". How to proceed?

  • @Lys - I believe you can simply add the property to the submitted object. So: formdata: { testId: '01234', upload_type: 'txt', [...]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.