Last active
July 15, 2021 12:44
-
-
Save codeBelt/9f0430eebeb21377015cf1273b0587fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nextConnect from 'next-connect'; | |
import multer from 'multer'; | |
// Returns a Multer instance that provides several methods for generating | |
// middleware that process files uploaded in multipart/form-data format. | |
const upload = multer({ | |
storage: multer.diskStorage({ | |
destination: './public/uploads', | |
filename: (req, file, cb) => cb(null, file.originalname), | |
}), | |
}); | |
const apiRoute = nextConnect({/* ... */}); | |
// Returns middleware that processes multiple files sharing the same field name. | |
const uploadMiddleware = upload.array('theFiles'); | |
// Adds the middleware to Next-Connect | |
apiRoute.use(uploadMiddleware); | |
apiRoute.post((req, res) => { | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment