I have a rest endpoint developed in spring. it consumes a multi part request with a string as one part(meta) and a two dimensional byte array(documents) as a second part. I was able to push the data using code. but I want to test the rest endpoint using postman
I have tried with sending the request part key as

can someone suggest me on how to send a two dimensional byte array through postman to spring rest endpoint.
You can use List<MultipartFile>/MultipartFile[] in the controller method argument which you can get byte[] for each uploaded files from each MultipartFile . It also allows you to get the original file name , size and the content type for each upload file.
Code wise it looks like:
@RequestMapping(value="/testMultiPart")
@ResponseBody
public ResponseEntity testMultiPart(
@RequestPart("meta") Map<String,String> meta,
@RequestPart("documents") List<MultipartFile> docs){
for(MultipartFile file: docs){
//Get the byte array for this file
byte[] bytes = file.getBytes();
System.out.println("OriginalFilename:" + file.getOriginalFilename());
System.out.println("FileSize:" + file.getSize());
System.out.println("ContentType:" + file.getContentType());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With