I know how I can upload a file from a client to an Express server using multer.
However, this can only be done using a middle ware function.
What I am looking for is a way to upload files from within the callback of the Express API.
My use case is this:
Client uploads a CSV file having URLs of images.
I will download those images from given URLs
Then I will upload those images in MongoDb within Express API callback
( I am looking for how to do the 3rd step. )
Something like this:
app.post('/uploadtoDB',multer.single('file'),(req,res)=>{
let urls = parseCSV_and_GetUrls(req.file);
urls.forEach((url)=>{
downloadImage(url)
});
//Scan directory to get downloaded images
let stream = fs.createReadStream('/path/to/downloadedFile');
//Upload the downloaded image to MongoDb
uploadfile_to_MongoDB(stream);
})