fix(docs): handle string destination in storage engine template#1394
Draft
Bojun-Vvibe wants to merge 1 commit intoexpressjs:mainfrom
Draft
fix(docs): handle string destination in storage engine template#1394Bojun-Vvibe wants to merge 1 commit intoexpressjs:mainfrom
Bojun-Vvibe wants to merge 1 commit intoexpressjs:mainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1278
Repo
expressjs/multer
Issue
#1278
Root cause
The
StorageEngine.mdcustom storage template assignedopts.destinationdirectly to
this.getDestinationand then invoked it as a function in_handleFile. If a user follows the convention used byDiskStorageandpasses
destinationas a string path, the template throws a TypeErrorbecause a string is not callable.
Fix
Updated the
MyCustomStorageconstructor inStorageEngine.mdto mirrorthe behavior of
storage/disk.js: whenopts.destinationis 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 existingstorage/disk.jsalready correctly handles string destinations and iscovered 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.