ENOENT: no such file or directory .?

后端 未结 14 1556
梦谈多话
梦谈多话 2020-12-09 17:15

This is error which am getting while post data and file. I have followed \'academind\' tutorial for building Restful API services, also i have been searching answer for this

14条回答
  •  独厮守ぢ
    2020-12-09 17:50

    This what worked for me. I changed './uploads/' into '__dirname' so that it can find the correct directory/filename anywhere on your computer.

    const storage = multer.diskStorage({
      destination: function(req, file, cb) {
        cb(null, __dirname);
      },
      filename: function(req, file, cb) {
        cb(null, new Date().toISOString() + file.originalname);
      }
    });
    

    Because when you set a specific folder name/directory you limit your image directory to be only or should be in that folder.

提交回复
热议问题