How to convert Buff to File Without locally saving it

How do you convert buff to a file? I have an endpoint that modifies images uploaded, and that endpoint returns buffs. Afterwards, I need these buffs to be uploaded in which I will call a service to do that, and the service I'm using requires File to upload the image. How would I do it so that the image is not saved and just passed to the function?
const imgBuff = images[0].image;

/* I need to save it as a variable and be passed as an imageFile, instead of saving it */
const fs = require('fs');
fs.writeFile('./image.jpg', Buffer.from(), (err) => {
if (err) throw err;
console.log('The file has been saved!');
});

await uploadImage(imageFile)
const imgBuff = images[0].image;

/* I need to save it as a variable and be passed as an imageFile, instead of saving it */
const fs = require('fs');
fs.writeFile('./image.jpg', Buffer.from(), (err) => {
if (err) throw err;
console.log('The file has been saved!');
});

await uploadImage(imageFile)
1 Reply
Joao
Joao11mo ago
It's not really up to you, if the uploadImage accepts a string that is a path to the file there's nothing you can do about it. Or does it accept a buffer as well? In which case you can simply provide that.
Want results from more Discord servers?
Add your server