1
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

4
  • req.params.filePath is only filled if the middleware appears after a path like in app.use("/upload/:filePath", ...). Is that the case for your middleware storage? Commented Aug 7, 2024 at 14:01
  • no beacause i dont know yet the wanted subfolder , and subfolders arent static , i need to get first the destination Commented Aug 7, 2024 at 14:12
  • Try http://${serversIP}/upload?filePath=${encodeURIComponent(saveMediaPath)} and evaluate the path as req.query.filePath. Commented Aug 7, 2024 at 14:13
  • still same first fetch fails after that works , same results as with the params Commented Aug 7, 2024 at 14:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.