richardgirges / express-fileupload

Simple express file upload middleware that wraps around busboy
MIT License
1.53k stars 261 forks source link

Error: Unexpected end of form at Multipart._final #369

Open seveun opened 11 months ago

seveun commented 11 months ago

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) } }

dedayoa commented 11 months ago

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.

hugoroussel commented 11 months ago

@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?

dedayoa commented 11 months ago

@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.

bitcoinbrisbane commented 10 months ago

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

bitcoinbrisbane commented 10 months ago

@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.

NorthernScythe commented 8 months ago

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?