【发布时间】:2012-10-19 09:10:53
【问题描述】:
将文件上传到我的服务器后,我尝试将其移动到另一个文件夹(同一磁盘),但出现错误
{[Error:ENOENT,rename 'F\myproject\1b231234nsdifhoi2323']
errno:34,
code:ENOENT,
path:'F\\myproject\\1b231234nsdifhoi2323'
}
在 Windows 上使用并使用
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 文件夹在同一个磁盘中
-
好吧,我编辑了 var target_path = 'F:\\myproject\\Video\\' + req.files.product_video.name;它比x有效
-
为了将来参考,您可以在此处查找 E*** 错误代码:github.com/joyent/node/blob/master/deps/uv/include/uv.h
-
@paynestrike,最好使用 var target_path = __dirname + "\\Video" + req.files.product_video.name (如果您的文件在 F:\myproject 中)