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 {
111111 . forEach ( param => {
112112 defaultMiddlewares . push ( multer ( param . extraOptions ) . array ( param . name ) ) ;
113113 } ) ;
114+
115+ defaultMiddlewares . push ( this . fixMulterRequestAssignment ) ;
114116 }
115117
116118 // user used middlewares
@@ -411,4 +413,21 @@ export class KoaDriver extends BaseDriver implements Driver {
411413 }
412414 }
413415
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+ }
414433}
You can’t perform that action at this time.
0 commit comments