question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem returning array of byte and representing form-data

See original GitHub issue

I 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. temp

How do I achieve the expected result?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
bnasslahsencommented, Jul 30, 2020

No, this is the swagger-ui default label.

1reaction
bnasslahsencommented, Jul 30, 2020

@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")))

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found