Busboy is not a constructor - Netlify Function+

Ahoy,

Attempting to create a function that handles a file upload and sends an email with the file uploaded.

Using the post How to Parse Multipart Form Data with Netlify Functions. I keep getting a “Busboy is not a constructor” error running the function.

require("dotenv").config()
const sgMail = require('@sendgrid/mail')
const fs = require("fs");
const Busboy = require('busboy');

exports.handler = async (event, context, callback) => {

// stuff

};

function parseMultipartForm(event) {
  return new Promise((resolve) => {

    const fields = {};

    const busboy = new Busboy({
      headers: event.headers
    });

    busboy.on(
      "file",
      (fieldname, filestream, filename, transferEncoding, mimeType) => {
     
        filestream.on("data", (data) => {
          fields[fieldname] = {
            filename,
            type: mimeType,
            content: data,
          };
        });
      }
    );

    busboy.on("field", (fieldName, value) => {
      fields[fieldName] = value;
    });

    busboy.on("finish", () => {
      resolve(fields)
    });

    busboy.write(event.body);
  });
}

Any help is greatly appreciated. Assuming I am doing something dumb :expressionless:

That guide is now older than the latest set of breaking changes :slight_smile:

If you see this one posted a few months after the post:

It says, no more constructor. You’re most likely using the latest version.