Firebase-functions: Multipart upload is broken

Created on 1 Dec 2017  路  10Comments  路  Source: firebase/firebase-functions

Version info

**firebase-functions: 0.7.3

**firebase-tools: 3.15.4

**firebase-admin: 5.5.1

Hi,
i want use multer with my firebase functions. If i use the function with the emulator, it works but if i deploy, the function return this error:
ERROR TypeError: Cannot read property 'filename' of undefined

This is my code => https://pastebin.com/G0PzgtVg

It's possible upload a file with the firebase functions?

Most helpful comment

... so is there any plan to fix this?

I get that this is in beta, but you're really going to just silently break something, not document it and not even keep the bug report open?

All 10 comments

i have found this error on stackoverflow => https://stackoverflow.com/questions/47242340/how-to-upload-a-file-using-express-on-firebase-cloud-functions

I have the same problem...

@sarovin Thanks for the report and glad you found the answer on Stackoverflow, presently that's the best way to deal with your issue.

... so is there any plan to fix this?

I get that this is in beta, but you're really going to just silently break something, not document it and not even keep the bug report open?

Did anybody looked at this in the past year?

Also interested in this. Any update?

What's up with this issue here? It's still broken. I just wasted half a day tracking down this bug. Please reopen and investigate this please.

For the next person that stumbles across this issue: the official docs have some code: https://cloud.google.com/functions/docs/writing/http#multipart_data

The guide tells you to use a low level library for multipart data processing, which is not ideal if you already are using some web framework. If you are using express for your http functions, you can use a forked version of multer middleware for processing multipart/form-data on cloud functions.

Here's what you can do.

const express = require('express')
const multer = require('multer')

const SIZE_LIMIT = 10 * 1024 * 1024 // 10MB
const app = express()

const multipartFormDataParser = multer({
  storage: multer.memoryStorage(),
  // increase size limit if needed
  limits: {fieldSize: SIZE_LIMIT},
  // support firebase cloud functions
  // the multipart form-data request object is pre-processed by the cloud functions
  // currently the `multer` library doesn't natively support this behaviour
  // as such, a custom fork is maintained to enable this by adding `startProcessing`
  // https://github.com/emadalam/multer
  startProcessing(req, busboy) {
    req.rawBody ? busboy.end(req.rawBody) : req.pipe(busboy)
  },
})

app.post('/some_route', multipartFormDataParser.any(), function (req, res, next) {
  // req.files is array of uploaded files
  // req.body will contain the text fields
})

Thanks @emadalam
I spent a tonne of hours debugging. I set up demo project on node.js and my code worked with multer but break in cloud functions.

Same here! Still not working! Firebase starts to be more a waste of time than saving time!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nicolasgarnier picture nicolasgarnier  路  56Comments

malikasinger1 picture malikasinger1  路  50Comments

OxyFlax picture OxyFlax  路  33Comments

beeirl picture beeirl  路  46Comments

ahaverty picture ahaverty  路  27Comments