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.

how about a doc / blog fix on netlify side then?

The blog post is over a year old - it’s not possible for us to keep blog posts updated with each and every framework or tool’s update. Moreover, it’s always recommended to refer to a tool’s official documentation.

Our docs on the other hand, are fairly well-maintained and regularly updated. If that example existed in Netlify docs, it would have been updated by now.