richardgirges / express-fileupload

Simple express file upload middleware that wraps around busboy
MIT License
1.52k stars 261 forks source link

dont use mv function in mac run #197

Closed dayney closed 4 years ago

dayney commented 4 years ago

"errno": -2, "code": "ENOENT", "syscall": "open",

RomanBurunkov commented 4 years ago

What does that mean?

ahmed-abdelfata7 commented 4 years ago

@dayney @RomanBurunkov I have the same error but after updating the path for the uploaded directory it's working fine

//before updating
sampleFile.mv(`../image/${sampleFile.name}`), function(err) {
     console.log(err);
  if (err) return res.status(500).send(err);
      res.send("File uploaded!");
 });

//after updating
    sampleFile.mv(path.join(__dirname, `../image/${sampleFile.name}`), function(
      err
    ) {
      console.log(err);
      if (err) return res.status(500).send(err);
      res.send("File uploaded!");
    });
//here the complete route
const path = require("path");
const uploadImage = app => {
  app.post("/upload", function(req, res) {
    if (!req.files || Object.keys(req.files).length === 0) {
      return res.status(400).send("No files were uploaded.");
    }
    let sampleFile = req.files.doc;
    sampleFile.mv(path.join(__dirname, `../image/${sampleFile.name}`), function(
      err
    ) {
      console.log(err);
      if (err) return res.status(500).send(err);
      res.send("File uploaded!");
    });
  });
};
RomanBurunkov commented 4 years ago

Closing since no details provided.

rmathias86 commented 2 years ago

I'm getting this error on mac as well. In my case (and might be the author's as well) this error occurs when the parent folder does not exist. Creating the bellow upload folder solves the issue.

[Error: ENOENT: no such file or directory, open '/Users/<hidden>/uploads/581C050B-A9AE-4533-937C-FD87190E4B40.jpg'] { errno: -2, code: 'ENOENT', syscall: 'open', path: '/Users/<hidden>/uploads/581C050B-A9AE-4533-937C-FD87190E4B40.jpg' }