sent file using axios using passthrough stream module in nodejs
Asked Answered
L

0

2

Imports

const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
const FfmpegCommand = require('fluent-ffmpeg');
const fs = require('fs');
const path = require('path');
const streamNode = require('stream');
const FormData = require('form-data');
const axios = require('axios').default;

Code here

async function audios() {
  let stream = fs.createReadStream(path.join(__dirname, '../videos/video.mp4'));
  let writeStream = fs.createWriteStream(path.join(__dirname, '../response/audios/' + +new Date() + '.wav'));
  let pass = new streamNode.PassThrough();
  let outputFile = path.join(__dirname, '../response/audios/' + +new Date() + '.wav');
  const ffmpeg = FfmpegCommand(file);

  ffmpeg
    .setFfmpegPath(ffmpegPath)
    .format('mp4')
    .toFormat('wav')
    .on('end', function () {
      console.log('file has been converted successfully');
    })
    .on('error', function (err, stdout, stderr) {
      console.log('an error happened: ' + err.message);
      console.log('ffmpeg stdout: ' + stdout);
      console.log('ffmpeg stderr: ' + stderr);
    })
    .on('end', function() {
      console.log('Processing finished !');
    })
    .stream(pass, { end: false })
    var bodyFormData = new FormData();
    bodyFormData.append('file', pass);
    let headers = bodyFormData.getHeaders(); 

    try {
      const jdata = await axios.post('http://localhost:4080/video',bodyFormData, {    maxContentLength: Infinity,
      maxBodyLength: Infinity,validateStatus: (status) => true ,headers:headers });
      console.log(jdata.data);
    } catch (error) {
      console.log("error" ,error.message);
    }

}

I am getting errors to sent passthrough stream through formdata ; issue is ffmpeg not creating readstrem so I am created passthrough from it and passed in formdata but not working right now

Lesh answered 12/8, 2022 at 8:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.