在 Spring Boot 中发送多部分响应 [英] send multipart response in spring boot
本文介绍了在 Spring Boot 中发送多部分响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究在 Spring Boot 中开发的 api.现在我有一个 API,我必须在其中发送包含一个二进制文件和 xml 的响应.两者将由多部分边界分隔.那么有没有办法做到这一点?
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?
推荐答案
在 spring boot 中尝试按照 multipart 发送响应的方式.
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);
}
这篇关于在 Spring Boot 中发送多部分响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文