Home > OS >  Directory folder to store document
Directory folder to store document

Time:11-23

I am trying to make document management project using nodejs,mongodb and react. I want to make directory folder that will store document and the sub is it file. But I could not find any reference that I could use to start making the directory. Is there any specific term that I should search to get any reference to start the project? Thank you.

CodePudding user response:

You can use Multer library for file uploads. It's super easy to use.

import multer from 'multer';

//specify where you want your files to be stored
var fileStorageEngine = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, './images')
    },
    filename: function (req, file, cb) {
        cb(null, Date.now()   '--'   file.originalname)
    }
})
var upload = multer({ storage: fileStorageEngine });

//pass it as a middleware to a route where you expect to get a file upload
app.use('/api/file/', upload.single('image'), someRouterHere);
  • Related