我尝试将它移动到其他文件夹(同一磁盘),我得到了thie错误在Windows和使用node.js的fs.rename()错误ENOENT
{[Error:ENOENT,rename 'F\myproject\1b231234nsdifhoi2323']
errno:34,
code:ENOENT,
path:'F\\myproject\\1b231234nsdifhoi2323'
}
上午
app.use(express.bodyParser({
uploadDir:'./Temp'
}));
这里是我的重命名代码
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');
}
});
});
};
它看起来像我得到的路径错了,但我不能看着办吧!
你在Windows上吗?如果是这样,你应该在路径名的驱动器部分包括冒号(':'),即'F:'。 –
但Temp和Video文件夹在相同的磁盘 – paynestrike
以及我编辑var target_path ='F:\\ myproject \\ Video \\'+ req.files.product_video.name;它可以工作thanx – paynestrike