我正在学习express.js一段时间。我只是使用angular.js学习图片上传,当文件上传到temp目录时,我必须将该文件移动到一个新目录。是的,该目录存在。但它仍然显示此错误。
User 572b94b4f30179941f5f7c5dis submittin { fieldName: 'file',
originalFilename: 'Capture.PNG',
path: 'C:\\Users\\arfo\\AppData\\Local\\Temp\\zK2-mOXhXflzjrKfxoACnuiw.PNG',
headers:
{ 'content-disposition': 'form-data; name="file"; filename="Capture.PNG"',
'content-type': 'image/png' },
size: 92643,
name: 'Capture.PNG',
type: 'image/png' }
{ [Error: ENOENT: no such file or directory, rename 'C:\Users\arfo\AppData\Local\Temp\zK2-mOXhXflzjrKfxoACnuiw.PNG' -> 'C:\Users\arfo\Desktop\all folders\sn\uploads\572b94b4f30179941f5f
7c5d2016-05-06T12:15:52.934ZCapture.PNG']
errno: -4058,
code: 'ENOENT',
syscall: 'rename',
但我有该目录存在
C:\Users\arfo\Desktop\all folders\sn\uploads
这是我的代码 轮廓controller.js
var User = require('../datasets/users');
var fs = require('fs-extra');
var path = require('path');
module.exports.updatePhoto = function (req,res) {
var file = req.files.file;
var userId = req.body.userId;
console.log("User " + userId+"is submittin" , file);
var uploadDate = new Date().toISOString();
var tempPath = file.path;
var targetPath = path.join(__dirname, "../../uploads/"+ userId + uploadDate +file.name);
var savepath = "/uploads/"+userId+ uploadDate +file.name;
fs.rename(tempPath,targetPath,function (err) {
if(err){
console.log(err)
}else{
console.log("filemoved");
/*User.findById(userId,function (err,userData) {
var user = userData;
user.image = savepath;
user.save(function (err) {
if (err){
console.log("Faile ");
}else{
console.log("Save success");
}
})
})*/
}
})
};