Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

multer gridfs storage

all you need is here! m/

conn.once('open', ()=> {
    //Init stream
    let gfs = Grid(conn.db, mongoose.mongo);
    gfs.collection('uploads');
})
    // creating storage engine
    var storage = new GridFsStorage({
        url: URI,
        file: (req, file) => {
          return new Promise((resolve, reject) => {
            crypto.randomBytes(16, (err, buf) => {
              if (err) {
                return reject(err);
              }
              const filename = buf.toString('hex') + path.extname(file.originalname);
              const fileInfo = {
                filename: filename,
                bucketName: 'uploads'
              };
              resolve(fileInfo);
            });
          });
        }
      });
      const upload = multer({ storage }); //upload is working as a middleware here!
Comment

PREVIOUS NEXT
Code Example
Javascript :: angular.json 
Javascript :: (node:15855) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 
Javascript :: what does return do in javascript 
Javascript :: arcgis for javascript 
Javascript :: jquery accordion toggle close open 
Javascript :: change parent state from child use effect in react js 
Javascript :: mdn .map 
Javascript :: fetch thingy 
Javascript :: axios send payload in get request 
Javascript :: make a component update every second react 
Javascript :: javascript prototype vs constructor function 
Javascript :: take a screenshot javascript of canvas 
Javascript :: nested callbacks javascript 
Javascript :: typeorm in 
Javascript :: regular expression 
Javascript :: javascript if one line 
Javascript :: sequelize attributes exclude all 
Javascript :: js try without catch 
Javascript :: js listen websocket 
Javascript :: mongoose virtual populate 
Javascript :: timezone in react js 
Javascript :: Promise.prototype.finally 
Javascript :: what is random state 
Javascript :: ArduinoJson.h 
Javascript :: how to add variables to an array in javascript 
Javascript :: javascript for...in loop 
Javascript :: instantiate js 
Javascript :: unexpected end of json input 
Javascript :: create react app 
Javascript :: how to delete object in array 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =