Skip to content

Instantly share code, notes, and snippets.

@codeBelt
Last active July 15, 2021 12:44
Show Gist options
  • Save codeBelt/9f0430eebeb21377015cf1273b0587fa to your computer and use it in GitHub Desktop.
Save codeBelt/9f0430eebeb21377015cf1273b0587fa to your computer and use it in GitHub Desktop.
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