[英]Uploaded images are not saving in targeted path in Node.js
I am just trying to upload and save images in my public/images
folder, I am getting the details of file by req.files
, after that I am getting this type of Error: EXDEV, rename 'c:\\Users\\abdul\\AppData\\Local\\Temp\\3348-qiy7kl.jpg'
我只是尝试上传图像并将其保存在我的
public/images
文件夹中,通过req.files
获取文件的详细信息,此后,我得到此类型的Error: EXDEV, rename 'c:\\Users\\abdul\\AppData\\Local\\Temp\\3348-qiy7kl.jpg'
here is my stuff
这是我的
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');
});
});
})
};
Can any body give any suggestion or give me any reference so that I can handle it? 任何机构都可以提出任何建议或给我任何参考,以便我可以处理吗?
Try this one 试试这个
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
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.