How to use the diskStorage function from multer

Find comprehensive JavaScript multer.diskStorage code examples handpicked from public code repositorys.

3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303




var firmwareImagePath = path.join(uploadsDir, './firmware.bin');
var spawn = require('child_process').spawn;
const multer = require('multer');
const storage = multer.diskStorage({
  destination: function(req, file, cb) {
    cb(null, uploadsDir);
  },
  // By default, multer removes file extensions so let's add them back
fork icon77
star icon133
watch icon22

+ 4 other calls in file

29
30
31
32
33
34
35
36
37
38
39
const multer = require("multer");
const Organization = require("./Models/organization");
const Course = require("./Models/course");
const Admin = require("./Models/admin");


var storage = multer.diskStorage({
  destination: "./public/images",
  filename: (req, file, cb) => {
    cb(null, Date.now() + "-" + file.originalname);
  },
fork icon2
star icon1
watch icon2

+ 4 other calls in file

289
290
291
292
293
294
295
296
297
298
299
300
301
302








//мултер не работи сега 
// const storage = multer.diskStorage({
//     destination: (req, file, cb) => {
//         cb(null, 'public/images')
//     },
//     filename: (req, file, cb) => {
fork icon0
star icon1
watch icon1

104
105
106
107
108
109
110
111
112
113
114
115
116


// // mypic is the name of file attribute
// }).single("mypic"); 




const videoStorage = multer.diskStorage({
  destination: 'videos', // Destination to store video 
  filename: (req, file, cb) => {
      cb(null, file.fieldname 
       // + '_' + Date.now() 
fork icon1
star icon0
watch icon1

+ 11 other calls in file

-3
fork icon0
star icon0
watch icon1

+ 4 other calls in file

29
30
31
32
33
34
35
36
37
38
39
40


const upload = multer({storage:storage});


//upload parameters for multer
// const upload = multer({
//   storage: multer.diskStorage({
//     //destination for files
//     destination: function (request, file, callback) {
//       callback(null, '/Users/yogesh.sharma/Desktop/TodoApp/ecommerce/public/uploads');
//     },
fork icon0
star icon0
watch icon1

+ 7 other calls in file

60
61
62
63
64
65
66
67
68
69
// set next image name
nextImageName = req.params.address + "v" + (fundToUpdate.imageVersion + 1) + ".jpeg";

// save the image in disk
multer({
  storage: multer.diskStorage({
    destination: "./uploads",
    filename(_, file, cb) {
      return cb(null, nextImageName);
    },
fork icon0
star icon0
watch icon1

+ 3 other calls in file

21
22
23
24
25
26
27
28
29
30
31
    },
    filename: filename
});


// Multi Image Upload
const multiImageStorage = multer.diskStorage({
    destination: function(req, file, cb) {
        cb(null, "./upload/products");
    },
    filename: filename
fork icon0
star icon0
watch icon1

+ 5 other calls in file

13
14
15
16
17
18
19
20
21
22
23
const filename = (req, file, cb) => {
    return cb(null, `${file.fieldname}_${Date.now()}${path.extname(file.originalname)}`)
};


// Profile Image Upload
const extraSingleStorage = multer.diskStorage({
    destination: function(req, file, cb) {
        cb(null, "./upload/extraImages");
    },
    filename: filename
fork icon0
star icon0
watch icon1

+ 5 other calls in file

2
3
4
5
6
7
8
9
10
11
12
const User = require('./../models/userModel');
const catchAsync = require('./../utils/catchAsync');
const AppError = require('./../utils/appError');
const factory = require('./handlerFactory');


// const multerStorage = multer.diskStorage({
//   destination: (req, file, cb) => {
//     cb(null, 'public/img/users');
//   },
//   filename: (req, file, cb) => {
fork icon0
star icon0
watch icon0