Encountering an error when attempting to upload documents and PDF files to Google Cloud through Firebase

My current project involves uploading basic documents using busboy / express.js to google cloud.

However, I encountered this error message:

Error: Cannot find module 'busboy/lib/types/node_modules/dicer'

Here is the code snippet for the upload request:

// Uploading a document for claim
exports.uploadDocument = (req, res) => {
  const BusBoy = require("busboy");

  const path = require("path");

  const os = require("os");

  const fs = require("fs");

  const busboy = new BusBoy({ headers: req.headers });

  let DocumentToBeUploaded = {};
  let DocumentFileName;
  // Modify this section to handle pdfs and docs etc

  busboy.on("file", (fieldname, file, filename) => {
    console.log(fieldname, file, filename);

    const documentExtension = filename.split(".")[
      filename.split(".").length - 1
    ];
    // 32756238461724837.png
    DocumentFileName = `${Math.round(
      Math.random() * 1000000000000
    ).toString()}.${documentExtension}`;
    const filepath = path.join(os.tmpdir(), DocumentFileName);
    DocumentToBeUploaded = { filepath, mimetype };
    file.pipe(fs.createWriteStream(filepath));
  });
  busboy.on("finish", () => {
    admin
      .storage()
      .bucket()
      .upload(DocumentToBeUploaded.filepath, {
        resumable: false,
        metadata: {
          metadata: {
            contentType: DocumentToBeUploaded
          }
        }
      })
      .then(() => {
        const docUrl = `https://firebasestorage.googleapis.com/v0/b/${config.storageBucket}/o/${DocumentFileName}?alt=media`;
        return db.doc(`/users/${req.Claim.ClaimId}`).update({ docUrl });
      })
      .then(() => {
        return res.json({ message: "document uploaded successfully" });
      })
      .catch(err => {
        console.error(err);
        return res.status(500).json({ error: "something went wrong" });
      });
  });
  busboy.end(req.rawBody);
};

I am currently attempting to upload a basic text document. It seems like a simple task, so I must be overlooking a minor error somewhere.

Any assistance would be greatly appreciated. Thank you :)

Answer №1

To successfully use busyboy, you must first install it by running the following command:

npm i busboy

To learn more about this npm package, visit the official link below:

https://www.npmjs.com/package/busboy

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

Using jQuery to dynamically retrieve a radio button

After struggling with this issue for quite some time, I have come to the realization that it's too complex for me to handle on my own. I could really use some assistance here. The problem at hand involves a page displaying various products, each of w ...

I am currently working with an input element that is set to hidden. I am trying to change its type to text using JavaScript, but I can't seem to figure out how to do it or if it is even possible

I'm stuck trying to change the type of an input element from hidden to text using JavaScript. I can't seem to figure out if it's even possible. Can someone please help me with this? Thanks! ...

I am looking for a way to display or conceal text depending on the presence of an image

Could you please help me with this? I am looking for a solution where text is displayed only when there is content in the src attribute of an img tag. Essentially, I need JavaScript code that can identify if an attribute has content and then make a paragra ...

Can the warning about a missing dependency in useEffect be incorrect at times?

After using hooks for some time, I still don't quite grasp why React insists on including certain dependencies in my useEffect that I don't want. My understanding of the 'dependencies' in a useEffect hook is as follows: You should add ...

A guide on extracting the text content from an anchor tag by using xPath() with a combination of selenium and Mocha

I have successfully chosen an <a> tag. My goal is to display the text of the anchor tag, but I am facing difficulties. The technologies being used are selenium, mocha, javascript, and phantomJS This is the detailed script: var assert = require(&ap ...

The random number generator often omits both the upper and lower limits

I am working with an array that contains letters from A to H. However, when using a random number generator, I have noticed that the letters A and H are rarely selected. How can I adjust my approach to make sure these two bounds are included more often? ...

The dynamic drop-down menu is giving incorrect values when the onchange function is called

Trying to implement Google Analytics tracking on my dynamic dropdown menu in WordPress has been a bit tricky. I want to be able to track when users click on any of the options and display the name of the selected value, not just the ID. However, I've ...

What are the best practices for managing POST data in Express.js?

Lately, I've been consistently encountering 500 errors from Express.js which seem to stem from a failure to retrieve a crucial string key required by the request. On the client side, numerous requests are being made to the same endpoint (/restore), a ...

What causes the React app to fail in maintaining the login session with the Node.js server?

Greetings, I have a NodeJS server set up in two separate files: app.js and routes.js. The app.js file includes code for setting up the server, error handling, middleware configuration, and routing logic. The routes.js file contains specific route configu ...

Creating a div resizing function using only JavaScript is a fun and useful project to tackle

Seeking help to create a div resizer using only pure JavaScript as jQuery is restricted. The current functionality works, but breaks when the position of the slider-div is not set to absolute. Any solutions to fix this issue would be greatly appreciated. ...

What is the process for running child_process when a user clicks on a view in an application

Just starting out with Node.js and utilizing express along with hogan or moustache templating for my views. I've successfully used the following code in my routing files, index.js as shown below: /* Test Shell Execute. */ router.get('/shell&apo ...

Leveraging flot in conjunction with NPM, React, and Node

I've been attempting to utilize flot in a Node.js React project, but I'm running into issues with the import. The browser console is showing the error: Uncaught TypeError: _jquery2.default.plot is not a function This error is essentially the sa ...

Transform your standard HTML buttons into a collective of radio buttons

Looking for a way to make some ordinary buttons function as radio buttons without adding another library to the project. Any suggestions on how this can be achieved using just HTML and JavaScript/jQuery? Appreciate any help, thank you. ...

Updating the value of each preceding sibling of every checked checkbox using jQuery upon form submission

After extensive research, I discovered that the most effective approach involves using a clever workaround to capture every tick and untick on a dynamic input row with multiple checkbox arrays. However, none of the solutions provided a viable method. I th ...

In Vue, props are not automatically assigned; be sure to avoid directly mutating a prop when assigning it manually to prevent errors

I am working with two Vue components: GetAnimal.vue and DisplayAnimal.vue. GetAnimal.vue sends a JSON object containing animal data to DisplayAnimal.vue using router push. DisplayAnimal.vue then displays this data. The process flow is as follows: I navigat ...

Display a collection of Mongoose objects in a React component

In my development stack, I rely on node js + React. The data I work with comes from mongoose and typically follows this format: { "_id": "61b711721ad6657fd07ed8ae", "url": "/esports/match/natus-vincere-vs-team-liquid- ...

Send an ArrayList to jQuery Flot

Good day. Apologies for any language barriers as English is not my first language. I am a novice in [see tags] and I have a web application that gathers a date and a serial number to execute a SQL query. The query returns some data (measurement values an ...

Node.js Program Attempting to Bind to Incorrect IP Address

I am currently facing an issue with my Node.js application running in a pod within a local Kubernetes cluster. Every time I attempt to start the app using app.listen(8989, '0.0.0.0'), I encounter an EACCES permission denied error. [2023-10-10T18: ...

Validation for prototype malfunctioning

I am currently using Prototype.js to implement form validation on my website. One of the fields requires an ajax request to a PHP file for validation purposes. The PHP file will return '1' if the value is valid and '0' if it is not. Des ...

How can I use JavaScript to trigger a button click event inside an iframe element

Is there a way to retrieve the inner HTML contents of a clicked element in an iframe loaded content using JavaScript? This code uses jQuery: var elements = document.getElementsByTagName('iframe'); [].forEach.call(elements, function(elem ...