Bus Boy's employment record shows no termination

I am working on a Next Js project that includes an upload image endpoint.

const busboy = require('busboy')

export default function handle(req, res)
{
    const bb = busboy({headers: req.headers});
    bb.on('file', (fieldname, file, filename, encoding, mimetype) => 
    {
        res.status(200).send({ message: 'file' });  //not functioning as expected
    });
    bb.on('close', () =>
    {
        res.status(201).send({ message: 'close' });
    });
    bb.on("finish", () => 
    {
        res.status(202).send({ message: 'finish' });
    });
    req.pipe(bb);
    res.status(203).send({ message: 'failed' });
}

I am encountering an issue with parsing form data using busboy. It seems to be skipping the file, close, and finish events and returning the failed message instead.

This is the event handler for submitting the form which triggers this endpoint:

function onFileUpload(e)
  {
    e.preventDefault();
    let form = new FormData();
    form.append("image", file, file.name);
    console.log(form)
    axios({
      method: "post",
      url: "http://localhost:3000/api/uploadImage",
      data: form,
      headers: form.getHeaders
      //{'Content-Type': 'multipart/form-data'}
    })
    .then((res) =>
    {
      console.log(res);
    });
  }

Can anyone help identify what might be causing this issue?

Answer №1

Dealing with Busboy on GCP cloud function presented me with a challenge too. I managed to resolve the issue by including bb.end(req.rawBody); right after setting up the callback for the "file".

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Enhance the current model in backbone.js by incorporating additional data

When a user selects an item on the webpage, more details need to be fetched and displayed. The API function /api/full_details has been implemented to return the additional data for that item. Challenge: How can I retrieve the additional data and append it ...

Obtain the date in ISO format without subtracting the timezone offset

I need to obtain a Date string without the timezone being added or subtracted. Currently, when I set my OS timezone to GMT +13 and create a new Date() object, the toISOString() method subtracts one day. For example, today is 11/02. If I adjust my OS time ...

What changes can be made to this javascript code in order to output a postal code without the last 2 characters?

function() { var address = $("#postcode").val(); var postcode = address.split(' '); postcode = "Postcode:"+postcode[(postcode.length-2)]; return postcode; } This JavaScript function extracts a postcode from an online form when a ...

Fixing PNG Fading Issue in Internet Explorer 8

I am currently utilizing the jQuery Cycle plugin to produce a fading animation effect. While this works perfectly on most browsers, I have encountered an issue with PNG files containing semi-transparent pixels in Internet Explorer 8. These partially transp ...

What is the reason behind the array.push() method not altering the array?

Here's the challenge: Eliminate all falsy values from a given array. Falsy values in JavaScript include false, null, 0, "", undefined, and NaN. Tips: Try converting each value to a Boolean. Below is my attempt at solving it: function bouncer(a ...

Execute HTML code within a text field

Is it possible to run html code with javascript inside a text box, similar to w3schools.com? I am working solely with html and javascript. Thank you. For example, I have two text areas - one for inserting html, clicking a button to run the code, and displ ...

How can I ensure that reactive form fields are properly validated in Angular2?

I am currently facing issues with validating Reactive form field in Angular 2. I have implemented a custom validator for this purpose, but it seems like my approach is not yielding accurate results as some of the test cases are failing. If anyone has insig ...

Issue detected with XMLHttpRequest - "The requested resource does not have the 'Access-Control-Allow-Origin' header."

Currently, I am working on the frontend development of an application using Angular 2. My focus is on loading an image from a third-party site via XMLHttpRequest. The code I have implemented for this task is as follows: loadFile(fileUrl) { const ...

Is my JQuery width() function giving incorrect value results?

Currently, I am facing a situation similar to the following: We have two popup windows that are quite alike. These popups are generated by a factory in JavaScript, allowing them to share common events and functions. One such function is our custom resize ...

What is the best way to store the outcome of a promise in a variable within a TypeScript constructor?

Is it possible to store the result of a promise in a variable within the constructor using Typescript? I'm working with AdonisJS to retrieve data from the database, but the process involves using promises. How do I assign the result to a variable? T ...

Choose and Send pictures through a Form with JavaScript

Currently, I am exploring different methods for allowing users to submit a form with the images they have selected. My idea is to present users with a set of images from which they can choose multiple options. Potential Solution 1: One approach could invo ...

Retrieve information from multiple RSS feeds using Next.js

As a newcomer to Next.js, I decided to experiment with a newsfeed tool to get more acquainted with the framework. My goal was to retrieve data from a collection of RSS feeds, but I encountered some unexpected issues in the process. How should I proceed? B ...

Tips for fixing prettier errors in express and TypeScript code

I have set up a simple Node/Express + Typescript application app.listen(PORT, (): void => { console.log(`app is running in ${environment} and listening on port ${PORT}!`); }); I am encountering an error and I am unsure of the cause? Replace PORT, wit ...

Is it possible for AWS Lambda to store global variables?

I've devised a basic increment counter shown below. global.counter = 0; exports.handler = (event, context, callback) => { // TODO implement callback(null, ++global.counter); }; Every time I test this function, the value increments as anti ...

What is the best way to incorporate currency formatting into a table using sumtr and datatables?

I have a table where I am utilizing sumtr for the table footer, and displaying all the information within datatables. My requirement is to show all the values as currency. However, I am unable to modify the values after sumtr because it won't be able ...

Specify a parameter within the generateStaticParams function when setting up static site generation in NextJS

On my SSG page, I am facing a challenge where I need to pass a language parameter to my api call function located inside the generateStaticParams function. The language is stored in cookies and currently inaccessible. Is there a way to successfully pass ...

What is the recommended file structure for pages that correlates with the `login//?username=` path in Next.js?

In my Next.js app, I've encountered an issue with a redirect URL that directs users to login//?username=. I attempted the following page setups: pages/login/index.tsx pages/login/[username].tsx pages/login/[rest].tsx pages/login/[...rest].tsx Howeve ...

Using Vue/Nuxt.js to compute the cumulative sum of hierarchically structured JSON data

When using Nuxt async data, I am retrieving a JSON object that includes a nested array in the following structure: "topic_list": { "topics": [ { "id": 9148, "title": "A", "views": 12 }, { "id": 3228, ...

Deleting the previous ion-view from DOM in Ionic v1 with Angular

I have been working on modifying an app built in Ionic v1. Within the app, there is a primary View titled 'Client's Profile' that contains links to two other Views: Support Request and Complaints. In the Support Request view, there is a Te ...

Utilizing Jquery's .load function will temporarily deactivate all other functions

Season's Greetings everyone! I have a unique personal messaging system on my website that utilizes jQuery for message display and manipulation. Let's delve into the specific file that controls this functionality: <!-- Fetching and displaying ...