How to use the multer.any function in multer

To help you get started, we’ve selected a few multer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yanatan16 / nanoajax / test / server.js View on Github external
function corsify(req, res) {
  // IE 6-7 requires this P3P header
  res.setHeader('P3P', 'CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"')

  // Standards-compatible CORS headers
  res.setHeader('Access-Control-Allow-Origin', req.get('origin') || '*')
  res.setHeader('Access-Control-Allow-Credentials', true)

  res.setHeader('Cache-Control', 'no-cache')
}

app.use(require('morgan')('dev'))
app.use(require('body-parser').urlencoded({extended:false}))
app.use(require('body-parser').json())
app.use(require('cookie-parser')())
app.use(require('multer')({ dest: 'temp/ '}).any())

app.get('/nanoajax.min.js', function (req, res) {
  fs.createReadStream(__dirname + '/../nanoajax.min.js', {encoding:'utf8'})
    .pipe(res)
})

app.get('/get', function (req, res) {
  res.send('OK')
})

app.post('/post', function (req, res) {
  if (req.body.arg === 'value' && req.body.foo === 'bar')
    res.send('OK')
  else
    res.status(400).send('Bad Request: ' + JSON.stringify(req.body))
})

multer

Middleware for handling `multipart/form-data`.

MIT
Latest version published 2 years ago

Package Health Score

76 / 100
Full package analysis