上传图片报错Error: EPERM, rename '...........' - CNode技术社区

上传图片报错Error: EPERM, rename '...........'
发布于 12 年前 作者 perny 5916 次浏览 最后一次编辑是 9 年前

//图片上传路由 app.post(’/uploadImg’,function(req, res, next){ console.log(req.files); console.log("name="+req.body.localUrl); console.log("文件的临时路径:"+req.files.imgFile.path);//这是文件的临时路径 console.log(‘get?dir=’+req.query.dir);

 var tpm_path = req.files.imgFile.path;
 var form = new formidable.IncomingForm();
 form.keepExtensions = true;//保留后缀 .jpg/.png
 var folderName = new Date().Format('yyyy-MM-dd');
 var dirPath = "./public/uploadimg/"+folderName;//指定路径
 console.log(dirPath);
 if(!fs.existsSync(dirPath)){//如果没有这个文件夹就创建文件夹
 fs.mkdirSync(dirPath);
 }
 //移动文件到指定路径
 fs.rename(tpm_path, dirPath, function(err){
 if(err){
 throw err;
 }
 //删除临时文件
 fs.unlink(tpm_path, function(err){
 if(err){
 throw err;
 }
 })
 })
11 回复

{ imgFile: { fieldName: ‘imgFile’, originalFilename: ‘pic.jpg’, path: ‘public\uploadimg1128円-gapt0h.jpg’, headers: { ‘content-disposition’: ‘form-data; name="imgFile"; filename="pic.jpg"’, ‘content-type’: ‘image/jpeg’ }, ws: { _writableState: [Object], writable: true, domain: null, _events: [Object], _maxListeners: 10, path: ‘public\uploadimg1128円-gapt0h.jpg’, fd: null, flags: ‘w’, mode: 438, start: undefined, pos: undefined, bytesWritten: 57771, closed: true, open: [Function], _write: [Function], destroy: [Function], close: [Function], destroySoon: [Function], pipe: [Function], write: [Function], end: [Function], setMaxListeners: [Function], emit: [Function], addListener: [Function], on: [Function], once: [Function], removeListener: [Function], removeAllListeners: [Function], listeners: [Function] }, size: 57771, name: ‘pic.jpg’, type: ‘image/jpeg’ } } name=C:\fakepath\pic.jpg 文件的临时路径:public\uploadimg1128円-gapt0h.jpg get?dir=image ./public/2014-05-26/

G:\NodeJsWorkspace\blog\routes\index.js:240 throw err; ^ Error: EPERM, rename ‘G:\NodeJsWorkspace\blog\public\uploadimg1128円-gapt0h.jpg’

和操作系统有关么?win7的

目录存在啊?怎么回事?

为什么不直接保存还要放在临时文件里面??

Error: EPERM 会不会是权限问题?

上传时都会报错到临时文件夹里的,如果不设置临时文件夹,会报错到C:User...目录下的

我查看了,文件夹都是可读写的设置

http://cnodejs.org/topic/4f40a4dc0feaaa4424081758 你的代码是不是有问题?看下这个文章

嗯,我看过这篇文章,按照这篇文章修改过也不行,我好像看到了他的评论也有这个问题

rename本身就是移动+删除,不需要unlink

删除unlink也不行,问题出现在rename上

回到顶部

AltStyle によって変換されたページ (->オリジナル) /