expressjs / expressjs/multer

Potential Issue with destination Parameter Type in Multer Custom Storage

Open
#1,278 0 comments 0 reactions 0 assignees View on GitHub
bug requires-triage
Dominant language
JavaScript
Stars
12.1k
Forks
1.1k
Avg merge
8d 2h
Merged PRs (30d)
21

Description

in this file https://github.com/expressjs/multer/blob/master/StorageEngine.md
its giving a template for making a custom storage engine but there is a problem I guess..

```js
function MyCustomStorage (opts) {
this.getDestination = (opts.destination || getDestination)
}
function MyCustomStorage (opts) {
this.getDestination = (opts.destination || getDestination)
}

MyCustomStorage.prototype._handleFile = function _handleFile (req, file, cb) {
this.getDestination(req, file, function (err, path) {
if (err) return cb(err)

var outStream = fs.createWriteStream(path)

file.stream.pipe(outStream)
outStream.on('error', cb)
outStream.on('finish', function () {
cb(null, {
path: path,
size: outStream.bytesWritten
})
})
})
}
```

its calling `this.getDestination` as function but it may not be a function if user provided "destination property" in the constructor.. or I am getting this wrong?

_Edited by Ulises to highlight syntax_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.