I am stacked with this error ENOENT: no such file or directory, open 'public/images/name.ext from express-fileupload I know there are lot of the same issue, but for me seems the solution do not work the ones I found here: No such file or directory error when uploading a file using Express-fileupload - Node.js
neither this one: ENOENT: no such file or directory .?
And I am still getting this error. I am not sure weather it is directory public declaration or mv('directory specification') or file name. Something got to be wrong definitely
Here is my project folder structure: enter image description here
and here is my app.js file
const express = require('express');
const cors = require('cors');
const fileUpload = require('express-fileupload')
const passport = require("passport");
const path = require("path");
const {db} = require("./database/db");
const authMiddleware = require('./app/middleware/authMiddleware')
const app = express();
// app.use(express.static(path.join(__dirname, "./public/")));
app.use(express.static(__dirname));
// app.use(express.static('public'))
// app.use('/public', express.static('public'));
// console.log('static path', express.static('public'))
app.use(fileUpload())
app.use('/api/asset/:assetId/uploadimage', async(req, res, next) => {
const file = req.files.file;
console.log('files bs',file)
try{
if(file === null){
throw new Error('Not file Specified')
}
// await file.mv(path.join(__dirname, `public/images/${file.name}`))
// await file.mv('public/image/' + file.name)
await file.mv('public/images/' + file.name)
res.status(200).json({fileName: file.name, filePath: `/uploads/${file.name}`});
}
catch(err){
console.log(err)
return res.status(400).send(err.message);
}
})
You can see the commented code, these are the ways I also tried and they did not work :(
and here is the error:
node_1 | files bs {
node_1 | name: '20191009_122021.jpg',
node_1 | data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 48 00 48 00 00 ff e1 02 8a 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 09 01 0f 00 02 00 00 00 08 00 00 ... 1488306 more bytes>,
node_1 | size: 1488356,
node_1 | encoding: '7bit',
node_1 | tempFilePath: '',
node_1 | truncated: false,
node_1 | mimetype: 'image/jpeg',
node_1 | md5: 'd2855d664bd5e5565a45da1ae06bd1ee',
node_1 | mv: [Function: mv]
node_1 | }
node_1 | [Error: ENOENT: no such file or directory, open 'public/images/20191009_122021.jpg'] {
node_1 | errno: -2,
node_1 | code: 'ENOENT',
node_1 | syscall: 'open',
node_1 | path: 'public/images/20191009_122021.jpg'
node_1 | }
Please help :)