重命名上传文件时出现ENOENT错误

时间:2018-06-16 12:51:34

标签: node.js express fs

所以我有一个表单向/ fUpload发出POST请求。

这是处理图片上传的路线:

router.post('/fUpload', function (req, res){
    var form = new formidable.IncomingForm();
    form.parse(req, function (err, fields, files) {
        // take old path from users file system
        var oldpath = files.fileToUpload.path;
        // rename file
        var temp = Date.now() + files.fileToUpload.name;
        // make new path to save the file to the project directory
        var newpath = '../public/uploads/' + temp;
        // change path of file to new path
        console.log(oldpath);
        console.log(temp);
        console.log(newpath);

        fs.rename(oldpath, newpath, function (err) {
            if (err) throw err;
            res.render('testFileUpload', { user : req.user });
        });

    });
});

提交表单时,节点服务器崩溃,我收到此错误消息:

Error: ENOENT: no such file or directory, rename 'C:\Users\FERNAN~1\AppData\Local\Temp\upload_0a419ccb6beecbc275c5b2c7a8603a1d' -> 'C:\Users\Fernando Montero\Desktop\public\uploads\1529152383437Android-G-b_46.jpg'

1 个答案:

答案 0 :(得分:0)

解决了,我有一对多"。"在我的路上