0

Node.JS fs.rename doesn't work Copying file from temporary folder to another partition gives error Just the same problem on windows (7) platform. Here is the form handler code I am using..

app.post('/contest/vacation-photo/:year/:month' , function(req, res){
var form = formidable.IncomingForm();
form.parse(req, function(err, fields, files){
    if(err) return res.redirect(303, '/error');
    if(err){
        res.session.flash = {
            type: 'danger',
            intro: 'Oops!',
            message: 'There was an error in processing your submission. ' +
                     'Please try again.',
        };
        return res.redirect(303, '/contest/vacation-photo');
    }
    var photo = files.photo;
    var dir = vacationPhotoDir + '/' + Date.now();
    var path = dir + '/' + photo.name;
    fs.mkdirSync(dir);
    fs.renameSync(photo.path, dir + '/' + photo.name);
    saveContestEntry('vacation-photo', fields.email, req.params.year, req.params.month, path);
    res.session.flash = {
        type: 'Hurray',
        intro: 'Good Luck!',
        message: 'You have entered into the contest.',
    };
    return res.redirect(303, '/contest/vacation-photo/entries');
});
});

This is the error I am getting..

fs.js:638 return binding.rename(pathModule._makeLong(oldPath), ^ Error: EXDEV, cross-device link not permitted 'C:\Users\GARGAN~1\AppData\Local\T emp\upload_f6d504b9c38177d30e03ba2091e02168'

Community
  • 1
  • 1
Smoking Sheriff
  • 471
  • 11
  • 23
  • What's the question? – Nocturno May 02 '15 at 05:43
  • @Nocturno How do I resolve this problem? – Smoking Sheriff May 02 '15 at 09:35
  • Here is the code I used to resolve the issue. With the help of the referred thread. `var photo = files.photo; var dir = vacationPhotoDir + '/' + Date.now(); var path = dir + '/' + photo.name; fs.mkdirSync(dir); var is = fs.createReadStream(photo.path); var os = fs.createWriteStream(dir + '/' + photo.name); is.pipe(os); is.on('end',function() { fs.unlinkSync(photo.path); });` – Smoking Sheriff May 02 '15 at 18:16

0 Answers0