Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: ENOENT when renaming file in node/express app

I am attempting to upload a file in my node/express app, and I am getting the following error:

{ [Error: ENOENT, rename '/tmp/64124a9886fdb03f1faee159bc533776']
  errno: 34,
  code: 'ENOENT',
  path: '/tmp/64124a9886fdb03f1faee159bc533776' }

/home/frankie/Projects/LP/routes/manager/deliverables.js:51
                            throw err;
                                  ^
Error: ENOENT, rename '/tmp/64124a9886fdb03f1faee159bc533776'

Here is the relevant code from my app:

if (req.files.file.name !== '' && req.files.file.size !== 0) {
    // this will move the uploaded file from the tmp folder to the uploads folder
    fs.rename(req.files.file.path, app.get('loc') +  "uploads/" + name + "-" + id + "/" + req.files.file.name, function (err) {
        if (err) throw err;

When I check what is in /tmp the file is there:

fiega@fiega:/tmp$ ll
total 56
drwxrwxrwt 12 root    root    4096 Dec 12 11:33 ./
drwxr-xr-x 23 root    root    4096 Sep 27 22:54 ../
-rw-rw-r--  1 fiega   fiega    903 Dec 12 11:33 13a26570f87297fd7f61785ef7d8772b

This is how I am using body parser:

app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.methodOverride());

Any ideas? I have tried changing the permissions of my entire my app but no dice.

like image 338
bejm Avatar asked Dec 12 '13 19:12

bejm


1 Answers

Have you checked the destination path you are using exists? (maybe you mean app.get('loc') + "/uploads/"...)

Oddly when this happens (source file exists and destination directory not), the error message you get only points to the source file... So check if that's not the problem.

Remember if you want to move the uploaded file to /a/b/c.txt, both /a and /a/b must already exist.

Also, if you need to move the file to a different partition you will have to use something like this, or you will get a EXDEV error.

like image 151
Salem Avatar answered Sep 19 '22 07:09

Salem