title: Corrupt image when uploading to Next.js API
body: <p>I'm trying to upload an image as form-data to a Nextjs api route. I use the package formidable to parse and save the file in a server folder. For the http request I use postman on the client.</p>
  
  <p>Here ist the backend code: </p>
  
  <pre><code>import formidable from 'formidable';
  
  export const config = {
    api: {
      bodyParser: false,
    },
  };
  
  export default async (req, res) =&gt; {
    const form = new formidable.IncomingForm();
  
    form.on('fileBegin', (name, file) =&gt; {
      file.path = "./" + file.name
  
    });
  
    form.parse(req, (err, fields, files) =&gt; {
      console.log( files);
    });
  
    res.statusCode = 200
    res.end()
  };
  </code></pre>
  
  <p>The image (jpeg) is saved in the folder. However, it appears to be corrupt or damaged.
  Here is the original image:</p>
  
  <p><a href="https://i.stack.imgur.com/xg8t2.jpg" rel="nofollow noreferrer">source image</a></p>
  
  <p><a href="https://i.stack.imgur.com/5mZ5r.jpg" rel="nofollow noreferrer">corrupt image</a></p>