Express always sends req.files for input file type even when it's empty

I have an input field like: `input(type='file', id='avatar', name='avatar', class='fivecol', accept='image/*')` and in my controller I check for `req.files.avatar`... Even when it's empty, the output still is logged and it temporarily stores (something) in `/uploads`. Here is a console log of `req.files.avatar` { avatar: { domain: null, _events: null, _maxListeners: 10, size: 0, path: 'uploads/aa7571f48cc1d0a3d1242d737f8c5fa0', name: '', type: 'application/octet-stream', hash: false, lastModifiedDate: null, _writeStream: { domain: null, _events: null, _maxListeners: 10, path: 'uploads/aa7571f48cc1d0a3d1242d737f8c5fa0', fd: 21, writable: false, flags: 'w', encoding: 'binary', mode: 438, bytesWritten: 0, busy: false, _queue: [], _open: [Function] }, length: [Getter], filename: [Getter], mime: [Getter] } } Why is it doing this? Also, there is a file that is `0 bytes` in that `/uploads` folder named `aa7571f48cc1d0a3d1242d737f8c5fa0` (or whatever other random hash gets generated each time). Additionally, why isn't express clearing those temporarily uploaded files out of `/uploads`?
Does it produce the files if you don't check req.files.avatar?

以上就是Express always sends req.files for input file type even when it's empty的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏