Skip to content

Instantly share code, notes, and snippets.

@arjunkdot
Forked from agmm/nextjs-file-upload-api.js
Created November 4, 2021 13:23
Show Gist options
  • Select an option

  • Save arjunkdot/f92cb93c16dfe84e30c18ef633d29d6c to your computer and use it in GitHub Desktop.

Select an option

Save arjunkdot/f92cb93c16dfe84e30c18ef633d29d6c to your computer and use it in GitHub Desktop.
Simple Nextjs File Upload — Backend API
// Backend
import formidable from 'formidable';
export const config = {
api: {
bodyParser: false,
},
};
export default async (req, res) => {
const form = new formidable.IncomingForm();
form.uploadDir = "./";
form.keepExtensions = true;
form.parse(req, (err, fields, files) => {
console.log(err, fields, files);
});
};
// For the frontend use:
// https://gist.github.com/AshikNesin/e44b1950f6a24cfcd85330ffc1713513
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment