Skip to content

fix(docs): handle string destination in storage engine template#1394

Draft
Bojun-Vvibe wants to merge 1 commit intoexpressjs:mainfrom
Bojun-Vvibe:fix/expressjs-multer-1278
Draft

fix(docs): handle string destination in storage engine template#1394
Bojun-Vvibe wants to merge 1 commit intoexpressjs:mainfrom
Bojun-Vvibe:fix/expressjs-multer-1278

Conversation

@Bojun-Vvibe
Copy link
Copy Markdown

Closes #1278

Repo

expressjs/multer

Issue

#1278

Root cause

The StorageEngine.md custom storage template assigned opts.destination
directly to this.getDestination and then invoked it as a function in
_handleFile. If a user follows the convention used by DiskStorage and
passes destination as a string path, the template throws a TypeError
because a string is not callable.

Fix

Updated the MyCustomStorage constructor in StorageEngine.md to mirror
the behavior of storage/disk.js: when opts.destination is a string,
wrap it in a function ($0, $1, cb) { cb(null, opts.destination) }
adapter; otherwise fall back to the function-or-default assignment.

Regression test

None. The change is documentation-only (StorageEngine.md); the existing
storage/disk.js already correctly handles string destinations and is
covered by test/disk-storage.js.

Risk

trivial

Verification

skipped: documentation-only change with no executable code path; existing
disk-storage tests cover the equivalent runtime behavior the docs now
reflect.

The custom storage engine template assigned opts.destination directly to

this.getDestination and then invoked it as a function, which fails when

a user passes a string path (as DiskStorage already supports). Mirror

DiskStorage's behavior by wrapping string destinations in a callback fn.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Potential Issue with destination Parameter Type in Multer Custom Storage

1 participant