express-fileupload icon indicating copy to clipboard operation
express-fileupload copied to clipboard

Error: Unexpected end of form at Multipart._final

Open seveun opened this issue 1 year ago • 6 comments

using express with firebase on serverless function

app.ts =>

`import express from 'express'; import bluebird from 'bluebird'; import cors from 'cors'; import passport from 'passport'; import bodyParser from 'body-parser'; import fileUpload from 'express-fileupload'; import router from './routes'; import session from './config/Session'; import * as auth from './auth';

(global.Promise as unknown as typeof bluebird) = bluebird;

const app = express(); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); app.use(fileUpload()); app.use(cors()); app.use(session); app.use(router); app.use(passport.initialize()); app.use(passport.session()); auth.init();

export default app;`

error => Error: Unexpected end of form at Multipart._final

my request is very simple :

export const patch = async (accessToken: string, body?: User, file?: any) => { let formData try { if (file) { formData = new FormData() formData.append('file', file) } const { data } = await axios.patch(URL, formData || body, { headers: { Authorization: Bearer ${accessToken}, }, }) return data } catch (err) { return console.log(err) } }

seveun avatar Dec 14 '23 12:12 seveun

Just ran into this issue as well with gcp cloud functions. https://github.com/mscdex/busboy/issues/296#issuecomment-1467129794 mentions a solution which I can confirm works in my tests.

dedayoa avatar Dec 16 '23 06:12 dedayoa

@dedayoa having the same issue in local env with the gcp cloud function. Don't understand how the mscdex/busboy#296 (comment) helps since express-fileupload does not exposes to my knowledge the busboy object. Can you go into more details on how you solved your issue?

hugoroussel avatar Dec 17 '23 15:12 hugoroussel

@hugoroussel I was indicating that replacing req.pipe with busyboy.end(req.rawBody) in https://github.com/richardgirges/express-fileupload/blob/98028e91d11b368df53ada2a183ecd863737baa4/lib/processMultipart.js#L184 got things working...but by no means the solution. I switched to cloud run instead.

dedayoa avatar Dec 18 '23 18:12 dedayoa

Same error. FYI I rolled back to 1.3.1 and it worked https://github.com/richardgirges/express-fileupload/releases

bitcoinbrisbane avatar Jan 11 '24 01:01 bitcoinbrisbane

@hugoroussel I was indicating that replacing req.pipe with busyboy.end(req.rawBody) in

https://github.com/richardgirges/express-fileupload/blob/98028e91d11b368df53ada2a183ecd863737baa4/lib/processMultipart.js#L184

got things working...but by no means the solution. I switched to cloud run instead.

Whats the work around? Im just using this on local machine.

bitcoinbrisbane avatar Jan 11 '24 01:01 bitcoinbrisbane

I recently got the same issue. It happened when I started using the Node.js cluster package to gain performance. It only happens when I try to upload binary files like PDF, MP4, etc... Reverting to a previous version of express-fileupload doesn't change anything for me... Anyone have any ideas?

NorthernScythe avatar Mar 11 '24 14:03 NorthernScythe