Reputation: 4668
after uploaded a file to my server i try to move it to another folder(same disk), and i got thie error
{[Error:ENOENT,rename 'F\myproject\1b231234nsdifhoi2323']
errno:34,
code:ENOENT,
path:'F\\myproject\\1b231234nsdifhoi2323'
}
am on windows and use
app.use(express.bodyParser({
uploadDir:'./Temp'
}));
here is my rename code
exports.upload = function(req, res,next){
console.log( req.body);
console.log(req.files);
var tmp_path = req.files.product_video.path;
var target_path = '\\Video\\' + req.files.product_video.name;
console.log(tmp_path); // Temp\1b231234nsdifhoi2323
console.log(target_path); // \Video\name
fs.rename(tmp_path, target_path, function(err) {
if (err) {
console.log(err)
};
fs.unlink(tmp_path, function() {
if (err){
console.log(err)
}else{
res.send('File uploaded to: ' + target_path + ' - ' + req.files.product_video.size + ' bytes');
}
});
});
};
it looks like i get the path wrong,but i cannot figure it out !
Upvotes: 3
Views: 13164
Reputation: 523
To avoid slash issue, you can use path.sep
so it will handle the slash \
based on the OS.
Upvotes: 0
Reputation: 2258
You are accessing an unexisting file - because a path does not.
Try edit path:
change "F\myproject\1b2"
to "F:/myproject/1b2"
or "F:\myproject\1b2"
If doesn't work, use: (__dirname will make a path relative to the script)
__dirname + "/../../myproject\1b2"
For debugging:
Try read
this file (if you get same error - it means that path is bad and rename
is fine)
Upvotes: 2