Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger UI is not showing fileupload button for RequestBody of type Byte Array #3364

Closed
lakshmitharun opened this issue Jul 4, 2020 · 2 comments
Labels
Milestone

Comments

@lakshmitharun
Copy link

lakshmitharun commented Jul 4, 2020

Question

@ApiOperation(value = WOPIConstants.API_FILE_UPDATE_CONTENT, response = boolean.class)
@ApiResponses(value = {
        @ApiResponse(code = HttpStatus.SC_OK, message = WOPIConstants.API_FILE_UPLOADED)
}
)
@PostMapping(value = WOPIConstants.REST_END_POINT_PUT_UPDATED_FILE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public boolean postFile(@RequestPart("files") Flux<FilePart> filePartFlux, @PathVariable final String name) {
    boolean isSuccessful = false;
    try {
        LOGGER.info(WOPIConstants.INFO_WOPISERVICE_PUTFILE_NAME + name);
        Flux<String> stringFlux = filePartFlux.flatMap(filePart ->
                filePart.content().map(dataBuffer -> {
                    byte[] bytes = new byte[dataBuffer.readableByteCount()];
                    LOGGER.info(WOPIConstants.INFO_WOPISERVICE_PUTFILE_RECEIVEDBYTES + bytes.length);
                    dataBuffer.read(bytes);
                    DataBufferUtils.release(dataBuffer);
                    byte[] encoded = Base64.getEncoder().encode(bytes);
                    return new String(encoded, StandardCharsets.UTF_8);
                }));
        final String encodedData = stringFlux.blockFirst();
        PutFileContentReq putFileContentReq;
        if (!"DATA".contains(name)) {
            putFileContentReq = new PutFileContentReq(insKey, encodedData);
        } else {
            putFileContentReq = new PutFileContentReq(name, encodedData);
        }
        LOGGER.info(WOPIConstants.INFO_WOPISERVICE_PUTFILE_PUTFILECONTENTREQ + putFileContentReq.toString());
        PutFileContentRes putFileContentRes = pegaClient.putUpdatedFileContent(baseURL, basicAuthHeader, putFileContentReq);
        LOGGER.info(WOPIConstants.INFO_WOPISERVICE_PUTFILE_PUTFILECONTENTREs + putFileContentRes.toString());
        isSuccessful = putFileContentRes.isSuccessful();
    } catch (Exception e) {
        LOGGER.error(WOPIConstants.EXCEPTION_WOPISERVICE_POSTFILE + e);
    }
    return isSuccessful;
}

Using springfox-swagger2 and springfox-swagger-ui Version : 2.9.2

Above mentioned is my code of a rest service which accepts a file in request body. Is there a way in Swagger UI to get fileupload button
In postman I was able to send file in the following way
image
In swagger Ui it is coming like this
image
Is there a way that I can annotate to determine that requestbody is a byte array of a file so that I can get File upload button in Swagger UI

@dilipkrish dilipkrish added this to the 3.0 milestone Jul 13, 2020
@lakshmitharun
Copy link
Author

@dilipkrish will this be available in v3

@dilipkrish
Copy link
Member

Yes it should be available as soon as it's released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants