Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

busboy never finishes process #1900

Closed
jousi592 opened this issue Jun 23, 2020 · 2 comments
Closed

busboy never finishes process #1900

jousi592 opened this issue Jun 23, 2020 · 2 comments

Comments

@jousi592
Copy link

jousi592 commented Jun 23, 2020

I am trying to upload some images to my cloud storage.
I am using form data to send the data down to the cloud function. The data arrives correctly, but the Busboy process never finishes processing it and the function timeouts after 60s.

Here is the implementation:

const firebase = require("firebase");
const Busboy = require("busboy");
require("firebase/storage");
const firebase_db = firebase_admin.database();
const firebase_storage = firebase.storage();


module.exports = (req, res) => {
  const busboy = new Busboy({headers: req.headers});
  const fields = {};
  const files = {};

  busboy.on('field', (fieldname, val) => {
    fields[fieldname] = val;
  });

  busboy.on('file', (fieldname, file, filename) => {
    files[fieldname] = file;
  });

  busboy.on('finish', async () => { // ----> Function never fires
    try {
      let project_id = await firebase_db.ref("/project_config/project_id").once("value")
      project_id = project_id.val()
   
      if (!project_id) return res.send({ message: "Project ID not found" })
      const new_image_storage_ref = firebase_storage.ref().child(`${project_id}/${fields.route}`)
      const snapshot = await new_image_storage_ref.put(files.image)
      const download_url = await snapshot.ref.getDownloadURL()
 
      res.send(download_url)
    } catch (error) {
      console.log("----- Error during saving content data ", error)
      res.send({ message: "Error during saving your image, please re-load page and try again or contact support." })
    }
  });
}

Do you have any idea what might be causing it?

@fhinkel
Copy link
Contributor

fhinkel commented Jun 23, 2020

Hi @jousi592 , thank you for the detailed bug report. Unfortunately, this issue tracker has limited visibility and scope - basically, it's just for reporting issues with the samples contained here and is only watched by the folks who work on these samples.

We are happy to help you move this bug to venues where it'll get the attention of the appropriate product teams.

I'm going to close this issue because the folks who own this repo have no actionable way to resolve it directly, but please let us know if there's anything we can do to help!

@VoiceDictionary
Copy link

at the end of the module.exports add:
busboy.end(req.rawBody);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants