@@ -240,6 +240,18 @@ describe("action parameters", () => {
240
240
return `<html><body>${ uploadedFileName } </body></html>` ;
241
241
}
242
242
243
+ @Post ( "/files-with-body" )
244
+ postFileWithBody ( @UploadedFile ( "myfile" ) file : any , @Body ( ) body : any ) : any {
245
+ uploadedFileName = file . originalname ;
246
+ return `<html><body>${ uploadedFileName } - ${ JSON . stringify ( body ) } </body></html>` ;
247
+ }
248
+
249
+ @Post ( "/files-with-body-param" )
250
+ postFileWithBodyParam ( @UploadedFile ( "myfile" ) file : any , @BodyParam ( "p1" ) p1 : string ) : any {
251
+ uploadedFileName = file . originalname ;
252
+ return `<html><body>${ uploadedFileName } - ${ p1 } </body></html>` ;
253
+ }
254
+
243
255
@Post ( "/files-with-limit" )
244
256
postFileWithLimit ( @UploadedFile ( "myfile" , { options : { limits : { fileSize : 2 } } } ) file : any ) : any {
245
257
return `<html><body>${ file . originalname } </body></html>` ;
@@ -682,6 +694,49 @@ describe("action parameters", () => {
682
694
} ) ;
683
695
} ) ;
684
696
697
+ describe ( "@UploadedFile with @Body should return both the file and the body" , ( ) => {
698
+ const requestOptions = {
699
+ formData : {
700
+ myfile : {
701
+ value : "hello world" ,
702
+ options : {
703
+ filename : "hello-world.txt" ,
704
+ contentType : "image/text"
705
+ }
706
+ } ,
707
+ anotherField : "hi" ,
708
+ andOther : "hello" ,
709
+ }
710
+ } ;
711
+
712
+ assertRequest ( [ 3001 , 3002 ] , "post" , "files-with-body" , undefined , requestOptions , response => {
713
+ expect ( response ) . to . be . status ( 200 ) ;
714
+ expect ( response ) . to . have . header ( "content-type" , "text/html; charset=utf-8" ) ;
715
+ expect ( response . body ) . to . be . equal ( `<html><body>hello-world.txt - {"anotherField":"hi","andOther":"hello"}</body></html>` ) ;
716
+ } ) ;
717
+ } ) ;
718
+
719
+ describe ( "@UploadedFile with @BodyParam should return both the file and the body param" , ( ) => {
720
+ const requestOptions = {
721
+ formData : {
722
+ myfile : {
723
+ value : "hello world" ,
724
+ options : {
725
+ filename : "hello-world.txt" ,
726
+ contentType : "image/text"
727
+ }
728
+ } ,
729
+ p1 : "hi, i'm a param" ,
730
+ }
731
+ } ;
732
+
733
+ assertRequest ( [ 3001 , 3002 ] , "post" , "files-with-body-param" , undefined , requestOptions , response => {
734
+ expect ( response ) . to . be . status ( 200 ) ;
735
+ expect ( response ) . to . have . header ( "content-type" , "text/html; charset=utf-8" ) ;
736
+ expect ( response . body ) . to . be . equal ( "<html><body>hello-world.txt - hi, i'm a param</body></html>" ) ;
737
+ } ) ;
738
+ } ) ;
739
+
685
740
describe ( "@UploadedFile with passed uploading options (limit) should throw an error" , ( ) => {
686
741
const validRequestOptions = {
687
742
formData : {
0 commit comments