Search code examples
javaspringfileswagger

Java Spring Swagger file upload


I have a file upload in my java spring app. But it does not show a file upload in swagger. What can I do?

I tried this and the one in the comment below..

@RequestMapping(
    value = "/add",
    method = POST,
    produces = {
        "multipart/form-data"
    }
)
public void addFile(@RequestParam("file") MultipartFile file) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        fileservice.AddAttachment(file);
}

Solution

  • In the @RequestMapping annotation, replace

        produces = {
            "multipart/form-data"
        }
    

    with

        consumes = {
            "multipart/form-data"
        }
    

    consumes defines the request media type, whereas produces defines the response media type.