Node.js Error renaming EXDEV

I played with the code that I found in a book about Node.js. This is a simple application that downloads images.

Error EXDEV is displayed here (500 Error: EXDEV, renaming).

Can someone give me a hint? Here is my code:

exports.submit = function(dir) {
    return function(req, res, next) {
        var img = req.files.photo.image;
        var name = req.body.photo.name || img.name;
        var path = join(dir, img.name);

        fs.rename(img.path, path, function (err) {
            if(err) return next(err);

            Photo.create({
                name: name,
                path: img.name
            }, function (err) {
                if(err) return next(err);
                res.redirect('/');
            });
        });
    };
};
+4
source share
2 answers

Renaming files is not possible with a cross device. I assume that your boot directory (which is equal by default /tmp) is on another partition / drive as the destination directory (contained in the variable dir).

Some solutions:

  • / ; , , express.bodyParser ( , connect.multipart) uploadDir, ;
  • Node TMPDIR, /​​, . Unix-:

    env TMPDIR=/path/to/directory node app.js
    
  • , Node :

    process.env.TMPDIR = '/path/to/directory';
    
  • , mv, ;
+18

Windows XP, app.js:

process.env.TMPDIR = '.';  //new
+1
source

All Articles