Problem returning array of byte and representing form-data
See original GitHub issueI have the following piece of code,
@PostMapping(value = "/create/{userId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<Object> saveFile(
@Parameter(description = "ID of the user") @PathVariable(value = "userId") final String userId,
@Parameter(description = "Avatar of the user", content = @Content(mediaType = MediaType.APPLICATION_OCTET_STREAM_VALUE)) @RequestParam(value = "avatar", required = true) final MultipartFile file
) {
...
}
@GetMapping(value = "/get", produces = MediaType.IMAGE_PNG_VALUE)
@ApiResponse(responseCode = "200", description = "OK", content = {@Content(array = @ArraySchema(schema = @Schema(implementation = Byte.class)))})
public ResponseEntity<byte[]> getFile() {
...
}
And below are the expected and the actual result.
How do I achieve the expected result?
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Problem representing form-data and returning array of byte in ...
I was faced the same problem last week. My solution was to replace the return type byte-Array by String via SpringDocUtils:
Read more >Problem representing form-data and returning array of byte in ...
[Solved]-Problem representing form-data and returning array of byte in Springdoc-Spring MVC ... For file format, the not type byte on the spec. You...
Read more >ArrayBuffer - JavaScript - MDN Web Docs
Chrome Edge
ArrayBuffer Full support. Chrome7. Toggle history Full support. Edge12. Tog...
@@species Full support. Chrome51. Toggle history Full support. Edge13. Tog...
ArrayBuffer() constructor Full support....
Read more >multipart/form-data - AndreuBotella.com
A multipart/form-data boundary is a byte sequence such that: ... Returns an object mapping names to an array of values represented by ...
Read more >How to extract file from multipart/form-data to upload to S3?
That is a representation of the byte array that is internal to the Java ... to the multi-part form parser, which always returns...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
No, this is the swagger-ui default label.
@debargharoy,
For file format, the not type byte on the spec. You should send
type: string, format: binary
.So, your requestBody for the post methods is correct.
To describe the return of type array of byte on your POST method, you can add the following description:
@ApiResponse(content = @Content(schema = @Schema(type = "string", format = "binary")))