nodejs中使用node-formidable写入tmp文件时候的权限问题
发布于 14小时前 作者 rayswim 57 次浏览 来自 问答

在项目中做post上传JSON文件时,通过node-formidable对post请求做处理,formidable缓存JSON文件后调用fs.renameSync(files.upload.path, savePath)报错,报错信息如下:

return binding.rename(pathModule._makeLong(oldPath), ^ Error: ENOENT, no such file or directory ‘tmp/upload_aa58a8a2acaecbeae75f09a62f51c59b’ at Error (native) at Object.fs.renameSync (fs.js:636:18) at /Users/Ray/Documents/Test/Web/node/07-upload/actionHandler.js:42:12 at IncomingForm.<anonymous> (/Users/Ray/Documents/Test/Web/node/07-upload/node_modules/formidable/lib/incoming_form.js:105:9) at IncomingForm.emit (events.js:104:17) at IncomingForm._maybeEnd (/Users/Ray/Documents/Test/Web/node/07-upload/node_modules/formidable/lib/incoming_form.js:553:8) at /Users/Ray/Documents/Test/Web/node/07-upload/node_modules/formidable/lib/incoming_form.js:230:12 at WriteStream.<anonymous> (/Users/Ray/Documents/Test/Web/node/07-upload/node_modules/formidable/lib/file.js:70:5) at WriteStream.g (events.js:199:16) at WriteStream.emit (events.js:129:20)

后来发现缓存文件权限都是不可执行,如图

total 24 drwxrwxrwx 4 Ray staff 136 7 24 13:04 . drwxr-xr-x 16 Ray staff 544 7 24 11:46 … -rwxrwxrwx@ 1 Ray staff 6148 7 24 13:04 .DS_Store -rw-r–r-- 1 Ray staff 929 7 24 13:01 upload_aa58a8a2acaecbeae75f09a62f51c59b

这个问题是否和权限有关呢?如果有关该如何处理呢?

1 回复

var form = new formidable.IncomingForm(); form.uploadDir = __dirname; 不知道是不是rename不可修改盘符的问题(这确实是没有权限

回到顶部