Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send multipart response in spring boot

I am working on apis which is developed in spring boot. Now I have one API in which I have to send response which contains one binary file and and xml. Both will be seperated by multipart boundary. So is there any way to do this?

like image 568
Darshan Sathwara Avatar asked Jun 03 '17 08:06

Darshan Sathwara


Video Answer


1 Answers

In spring boot try following the way to send a response in multipart.

   @RequestMapping(method = { RequestMethod.GET },value = "/multipartdata",produces=MediaType.MULTIPART_FORM_DATA_VALUE)
    public ResponseEntity<MultiValueMap<String, Object>> gerMultipartData()
            throws Exception {
        MultiValueMap<String, Object> formData = new LinkedMultiValueMap<String, Object>();
        formData.add("first_name",  "ganesh");
        formData.add("last_name", "patil");
        formData.add("file-data_1", new FileSystemResource("C:\Users\ganesh\img\logo.png"));
        formData.add("file-data_2", new FileSystemResource("C:\Users\ganeshg\Desktop\download.jpg"));
        formData.add("file-data_3", new FileSystemResource("C:\Users\ganeshg\Desktop\odstext.txt"));
        formData.add("file-data_4", new FileSystemResource("D:\Agent\152845.docx"));
        formData.add("file-data_5", new FileSystemResource("D:\testxls.xlsx"));
        return new ResponseEntity<MultiValueMap<String, Object>>(formData, HttpStatus.OK);
    }
like image 56
Ganesh Gudghe Avatar answered Sep 18 '22 19:09

Ganesh Gudghe