How to request String param together with Flux<Part> in reactive spring

Viewed 39

I am trying to upload file using Reactive spring fremework.If I only reqeset file by postman. It works fine. When I added addtional parameter Stirng as uploadType. It is always null. I tried postman as following:-

My controller code:-

@RestController
@RequestMapping(path = "/upload")
public class ReactiveUploadResource {
    Logger LOGGER = LoggerFactory.getLogger(ReactiveUploadResource.class);

    @RequestMapping(method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public Flux<String> uploadHandler(@RequestBody Flux<Part> parts, String uploadType) {
        return (Flux<String>) parts
                .filter(part -> part instanceof FilePart)
                .ofType(FilePart.class) // convert the flux to FilePart
                .flatMap(item -> saveFile(item, uploadType)); // save each file and flatmap it to a flux of results
    }
}

Postman:-

enter image description here

I always get uploadType null. What is wrong? How can pass String or Enum in this reqeust?

0 Answers
Related