Skip to content

Potential Issue with destination Parameter Type in Multer Custom Storage #1278

@anoniz

Description

@anoniz

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..

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions