Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

multer in express.js

const express = require('express')
const multer  = require('multer')
const upload = multer({ dest: 'uploads/' })

const app = express()

app.post('/profile', upload.single('avatar'), function (req, res, next) {
  // req.file is the `avatar` file
  // req.body will hold the text fields, if there were any
})

app.post('/photos/upload', upload.array('photos', 12), function (req, res, next) {
  // req.files is array of `photos` files
  // req.body will contain the text fields, if there were any
})

const cpUpload = upload.fields([{ name: 'avatar', maxCount: 1 }, { name: 'gallery', maxCount: 8 }])
app.post('/cool-profile', cpUpload, function (req, res, next) {
  // req.files is an object (String -> Array) where fieldname is the key, and the value is array of files
  //
  // e.g.
  //  req.files['avatar'][0] -> File
  //  req.files['gallery'] -> Array
  //
  // req.body will contain the text fields, if there were any
})
Comment

express multer

$ npm install --save multer

var express = require("express");
var multer = require('multer');
var upload = multer({dest:'uploads/'});
Comment

PREVIOUS NEXT
Code Example
Javascript :: generator js 
Javascript :: js 2d array includes 
Javascript :: unit testing for react 
Javascript :: javascript for validation 
Javascript :: react window navigate 
Javascript :: query mongodb - nodejs 
Javascript :: namespace javascript 
Javascript :: drag n drop file upload react 
Javascript :: stripe payment js 
Javascript :: passport js npm 
Javascript :: map function javascript 
Javascript :: Requiring express 
Javascript :: javascript find textarea 
Javascript :: new function javascript 
Javascript :: add event listeners 
Javascript :: what does the useReducer do in react 
Javascript :: setjavascriptenabled why it is used 
Javascript :: react native how to pass id from list to function 
Javascript :: react native get source maps 
Javascript :: drill into tree to find key javascript 
Javascript :: moment_timezone_1.default(...).tz(...).format is not a function 
Javascript :: run strapi plugin at startup 
Javascript :: js camelcase 
Javascript :: how to push into an array javascript 
Javascript :: js 10.2 * 100 result of 10.199999 
Javascript :: how to store and extract local storage 
Javascript :: Function to convert an Array to an Associative array 
Javascript :: javascript curtocircuito 
Javascript :: valueof in react native 
Javascript :: list pci express version command line 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =