I'm having trouble sending large videos, the readFile method only reads small files, I tried with readStream but I didn't get a satisfactory result, with readFile if the file is smaller than 5mb it reads and sends normally to the middleware. I currently use the 'rn-fetch-blob' library.
const base64 = await fs.readFile(gravacao.videoMediaFile, "base64");
let formdata = {
codUsuario : gravacao.codUsuario,
codCadeiaCustodia : gravacao.codCadeiaCustodia,
videoTamanho : gravacao.videoTamanho,
videoMimeType : gravacao.videoMimeType,
videoNome: gravacao.videoNome,
gravacao.videoBase64 = base64;
};
console.log("form data - " + formdata);
let response = await this.api.postMiddleware(this.api.middlewareBase + "registrar", formdata);
I get it in the middleware like this.
export async function salvar(obj) {
var fs = require('fs');
try{
fs.writeFile(`./videos/video.mp4`, obj.videoBase64, 'base64', function (err){
console.log(err);
});
console.log('mudou nome video');
} catch(err){
console.log(JSON.stringify(e));
}
return await ColetaAssistidaModel.create(obj);
};
I need to send videos of an average of 30mb for the middleware to receive and save in a folder and then send by fetch.