const response = await fetch(`http://${serversIP}/upload/${encodeURIComponent(saveMediaPath)}`, {
method: 'POST',
body: formData,
headers: {
'Content-Type': 'multipart/form-data',
}
});
const storage = multer.diskStorage({
destination: (req, file, cb , err) => {
let savePath = imagesDir
//console.log("its",req.params.filePath)
if(req.params.filePath!="startPoint"){
savePath = path.join(imagesDir,req.params.filePath)
}
cb(null, savePath); // Save all files to the 'images' directory
},
filename: (req, file, cb) => {
cb(null, Date.now() + path.extname(file.originalname));
}
});
i am trying to send the destination as a url param
in order to save it where it needs to be but almost always , the first time i am fetching fails but after the first time works flawless , any ideas
i have tried --> send it as header --> append it in the json
i dont know how to solve it , and i cant find something usefull on the internet any ideas would be more than welcomed
req.params.filePathis only filled if the middleware appears after a path like inapp.use("/upload/:filePath", ...). Is that the case for your middlewarestorage?http://${serversIP}/upload?filePath=${encodeURIComponent(saveMediaPath)}and evaluate the path asreq.query.filePath.