swagger-finatra icon indicating copy to clipboard operation
swagger-finatra copied to clipboard

File formParam

Open dayyan opened this issue 8 years ago • 5 comments

Unless I'm doing this incorrectly, seems like file upload isn't supported yet.

Example in pet store: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/api/PetApi.scala#L128-L133

Example in ui: http://petstore.swagger.io/#!/pet/uploadFile

I've tried both a case class with a dataType file, and specifying File as the TypeTag.

dayyan avatar Nov 24 '16 00:11 dayyan

Can you provide the sample code of doing file upload with Finatra?

xiaodongw avatar Nov 30 '16 04:11 xiaodongw

Here's what I tried:

postWithDoc("/file") { o =>
   o.summary("Submit a new file.")
    .formParam[File]("file")
    .bodyParam[Metadata](name = "Metadata", description = "Metadata on the binary.")
 } { request: Request => response.ok.toFuture }

I also tried:

case class ApplicationBinary(
   @ApiModelProperty(dataType = "java.io.File")
   fileToUpload: java.io.File
)

And using that as the dataType.

dayyan avatar Dec 12 '16 19:12 dayyan

I cannot find any example about how to do file upload with Finatra. Your example having a File field in case class, will this work? Can you provide a full example about handling the file upload, not just the swagger part?

xiaodongw avatar Dec 14 '16 02:12 xiaodongw

@xiaodongw Finatra uses RequestUtils to handle file upload.

forthy avatar Dec 21 '16 04:12 forthy

Sorry for the delay. This is how I process in a nutshell:

  postWithDoc("/file") { o =>
    o.summary("submit a new file")
     .produces("application/json")
     // examples don't work.
     .formParam[File](name = "file", description = "binary to upload", true)
     .consumes("multipart/form-data")
     .responseWith(...
  } { request: Request =>
    val params = RequestUtils.multiParams(request)
    ourService.submitBinary(formRequest.file, formRequest.filename)
    ...

dayyan avatar Jan 26 '17 19:01 dayyan