Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending two dimensional byte array(multiple files) through postman as a multi part request

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

  1. documents[0] - file ,documents1 - file enter image description here
  2. documents - multiple files
  3. documents [ ] - files
  4. specifically added the content-type as multi-part form data
  5. specifically added content-type for each key as well. the above approaches didn't work.

enter image description here can someone suggest me on how to send a two dimensional byte array through postman to spring rest endpoint.

like image 759
Kaiizok Avatar asked Aug 26 '26 15:08

Kaiizok


1 Answers

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());

    }
}
like image 173
Ken Chan Avatar answered Aug 28 '26 07:08

Ken Chan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!