When I'm trying to upload images and save in public/upload_files folder through postman it shows this error
node -v v10.15.3
npm -v 6.9.0
"Error: ENOENT: no such file or directory"
This is my code
const express = require('express');
const router = express.Router();
const multer = require('multer');
const storage = multer.diskStorage({
destination: function(req, file, cb) {
cb(null,'./public/uploaded_files');
},
filename: function(req, file, cb) {
cb(null,new Date().toISOString() + file.originalname);
}
});
const upload = multer({storage:storage});
router.post('/', upload.single('file'), (req,res,next) => {
console.log(req.file);
});
module.exports = router;
I'm just trying to save the images in the following folder public/upload_files
It's an abbreviation of Error NO ENTry (or Error NO ENTity), and can actually be used for more than files/directories. It's abbreviated because C compilers at the dawn of time didn't support more than 8 characters in symbols. Follow this answer to receive notifications. edited Jun 4, 2019 at 14:30. community wiki.
The code ENOENT means that npm fails to open a file or directory that's required for executing the command. The npm start command is used to run the start script in the package. json file.25-Jun-2022.
I made few changes to my code and it worked.
I added this line
cb(null,path.join(__dirname,'../upload'))
and this
cb(null,Date.now() + path.extname(file.originalname))
code
var storage = multer.diskStorage({
destination: function(req, file, cb)
{
cb(null,path.join(__dirname,'../upload'))
},
filename: function(req, file, cb)
{
cb(null,Date.now() + path.extname(file.originalname))
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With