madhums / madhums/node-imager

Doesn't compatible with multer

Open
#85 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
267
Forks
60
PR merge metrics
No merged PRs in 30d

Description

Please fix.

The file uploaded with multer has the following json object:

{ fieldname: 'avatar_image',
originalname: 'blob',
name: '1897942a7e194802e27db8e71c7a0fd4',
encoding: '7bit',
mimetype: 'image/jpeg',
path: '/var/folders/m8/x6wjwggd7sl4qv01sb_1r6gc0000gr/T/1897942a7e194802e27db8e71c7a0fd4',
extension: '',
size: 12934,
truncated: false,
buffer: null }

The object is different from the old express file upload.

Here is the error:
/Users/endaxue/workspace/profile/node_modules/imager/lib/imager.js:843
return (file['type'] || file['mimetype']) || file.headers['content-type'];
^
TypeError: Cannot read property 'content-type' of undefined
at getFileType (/Users/endaxue/workspace/profile/node_modules/imager/lib/imager.js:843:60)
at prepare (/Users/endaxue/workspace/profile/node_modules/imager/lib/imager.js:122:18)
at /Users/endaxue/workspace/profile/node_modules/imager/node_modules/async/lib/async.js:111:13
at Array.forEach (native)
at _each (/Users/endaxue/workspace/profile/node_modules/imager/node_modules/async/lib/async.js:32:24)
at Object.async.each (/Users/endaxue/workspace/profile/node_modules/imager/node_modules/async/lib/async.js:110:9)
at /Users/endaxue/workspace/profile/node_modules/imager/lib/imager.js:134:13
at /Users/endaxue/workspace/profile/node_modules/imager/node_modules/async/lib/async.js:232:13
at /Users/endaxue/workspace/profile/node_modules/imager/node_modules/async/lib/async.js:119:25
at /Users/endaxue/workspace/profile/node_modules/imager/node_modules/async/lib/async.js:24:16

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/imager.js at getFileType around line 843, then follow its call from prepare. Compare the multer file object shown in the issue with the fields this entry point reads, and verify that processing a multer upload no longer raises the undefined headers error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.