上传的图片未保存在 Node.js 中的目标路径中

Uploaded images are not saving in targeted path in Node.js

我只是想在我的 public/images 文件夹中上传和保存图像,我通过 req.files 获取文件的详细信息,之后我得到这种类型的 Error: EXDEV, rename 'c:\Users\abdul\AppData\Local\Temp48-qiy7kl.jpg'

这是我的 stuff

 app.post('/upload',function(req,res){
    var tmp_path = req.files.file.path;
    var target_path = './public/images/' + req.files.file.originalFilename;
    fs.rename(tmp_path, target_path, function(err) {
        if (err) throw err;
        fs.unlink(tmp_path, function() {
            if (err) throw err;
            res.send('File uploaded to: ' + target_path + ' - ' + req.files.file.size + ' bytes');
        });
    });
    })
}; 

有哪位大神可以给点建议或者参考,让我处理一下吗?

试试这个

    console.log("File Name " + req.files.file.name);
    console.log("File Path " + req.files.file.path);

    fs.readFile(req.files.file.path, function (err, data) {
        var newPath = "public/images/" + req.files.file.originalFilename;
        console.log(newPath);
        /// write file to uploads/fullsize folder
        fs.writeFile(newPath, data, function (err) {
            /// let's see it
        });