Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue uploading files - Error: ENOENT: no such file or directory - ubuntu and windows #367

Open
c4cookie opened this issue Sep 24, 2022 · 1 comment

Comments

@c4cookie
Copy link

c4cookie commented Sep 24, 2022

Hey so first thing nice project, I really want to get it working but just can't seem to upload any files.

Issue:
If I drag and drop an image into an article, or if I try and manually upload an image in the files section, the following error occurs:
Error: ENOENT: no such file or directory, open '/root/KnowledgeBase/routes/public/uploads/5927cbaa713e1dd4cae59d13470c1a79'
after restarting the application, I see the file is in the 'files' area, but its 0KB and not useable.

The issue occurs on both windows and ubuntu (I don't want to use windows, but I did try on both).

Testing:

  • I tried just running npm run start and also PM2, the issue is the same
  • also run with sudo -> sudo env PATH=$PATH pm2 start app.js
  • I can confirm the folder location has read and write permissions (see screenshot)
  • (I attempted to upload Capture.PNG and testScreenshot.png, the screenshot below shows they are 0KB and they also caused the app to crash when uploading)
    image
  • If I upload an image into the directory manually and then reference the image on the article, it works fine (same for images hosted on an external site), I just cant 'upload' an image.

would appreciate any advice! this KB solution is exactly what im after.


EDIT

I've had a further look and noticed something else, the error message throws the same directory every time and its trying to find the file in the 'routes' folder?

the picture below shows im trying to upload the file 'testScreenshot.png' to the folder /uploads/testuploads
but the error message says no such file in /routes/public/uploads/ ?

the image should be uploading to /root/KnowledgeBase/public/uploads/testuploads
so im not sure why its checking in the routes folder.

image


EDIT 2

I decided to move to a different open source kb solution

@citro333
Copy link

Hello,

I know it is little older but if anybody has the same problem here is the solution for the latest node.js version
Edit index.js file in router folder and change the saving procedure

from:

const source = fs.createReadStream(file.path);
const dest = fs.createWriteStream(path.join(upload_dir, file.originalname));
source.pipe(dest);
source.on('end', () => { });

to:

const source = file.path;
const dest = path.join(upload_dir, file.originalname.replace(/ /g, '_'));
fs.copyFile(source,dest, (err)=> {
  if (err) throw err;
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants