I have a svg in form of a string. I want to convert that string into a file and send it via FormData to another API.
I found a way how it works but that includes creating a file locally (with fs) and then creating a readStream from the just created file. Processing many files this is super slow and ends in a timout most of the time.
fs.writeFile('file.svg', svgString, async () => {
const fr = fs.createReadStream('file.svg');
const formData = new FormData();
formData.append('media', fr);
const response = await Axios.post(route, formData, {...}
});
});
Here is my (failing) approach using Buffer and Readable:
// Create readable from svg string
const b = Buffer.from(svgString, 'utf-8');
const r = Readable.from(b);
const formData = new FormData();
formData.append('media', fr);
const response = await Axios.post(route, formData, {...});
This method is not giving the same result as the first. I then get a error from the external API.
The question is how do I get the same result as in the first approach, without writing local files to the disk.
Thanks in advance!