【问题标题】:ENOENT error when renaming uploaded file重命名上传的文件时出现 ENOENT 错误
【发布时间】:2018-11-26 00:53:36
【问题描述】:

所以我有一个向 /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'

【问题讨论】:

    标签: node.js express fs


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2020-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-10
      • 1970-01-01
      • 1970-01-01
      • 2020-12-26
      相关资源
      最近更新 更多