File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,8 @@ export class KoaDriver extends BaseDriver implements Driver {
111
111
. forEach ( param => {
112
112
defaultMiddlewares . push ( multer ( param . extraOptions ) . array ( param . name ) ) ;
113
113
} ) ;
114
+
115
+ defaultMiddlewares . push ( this . fixMulterRequestAssignment ) ;
114
116
}
115
117
116
118
// user used middlewares
@@ -411,4 +413,21 @@ export class KoaDriver extends BaseDriver implements Driver {
411
413
}
412
414
}
413
415
416
+ /**
417
+ * This middleware fixes a bug on koa-multer implementation.
418
+ *
419
+ * This bug should be fixed by koa-multer PR #15: https://github.com/koa-modules/multer/pull/15
420
+ */
421
+ private async fixMulterRequestAssignment ( ctx : any , next : Function ) {
422
+ if ( "request" in ctx ) {
423
+ if ( ctx . req . body ) ctx . request . body = ctx . req . body ;
424
+ if ( ctx . req . file ) ctx . request . file = ctx . req . file ;
425
+ if ( ctx . req . files ) {
426
+ ctx . request . files = ctx . req . files ;
427
+ ctx . files = ctx . req . files ;
428
+ }
429
+ }
430
+
431
+ return await next ( ) ;
432
+ }
414
433
}
You can’t perform that action at this time.
0 commit comments