multer icon indicating copy to clipboard operation
multer copied to clipboard

Potential Issue with destination Parameter Type in Multer Custom Storage

Open anoniz opened this issue 1 year ago • 0 comments

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

anoniz avatar Oct 12 '24 13:10 anoniz