Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将响应作为多部分发送_Java_Rest_Spring Boot_Jersey_Multipart - Fatal编程技术网

Java 如何将响应作为多部分发送

Java 如何将响应作为多部分发送,java,rest,spring-boot,jersey,multipart,Java,Rest,Spring Boot,Jersey,Multipart,我有一个API,其中我必须发送一个包含一个二进制的响应 我尝试了StackOverflow的一些例子,但没有得到任何解决方案 我在泽西岛试过 但是运气不好,请帮忙。发送单个文件: 返回zip多部分响应也有两种选择 使用下面的代码一次发送多个数据对象 MultiValueMap<String, Object> body = new LinkedMultiValueMap<>(); body.add("firstName", getFirstName()); body.a

我有一个API,其中我必须发送一个包含一个二进制的响应

我尝试了StackOverflow的一些例子,但没有得到任何解决方案

我在泽西岛试过

但是运气不好,请帮忙。

发送单个文件:

返回zip多部分响应也有两种选择

使用下面的代码一次发送多个数据对象

MultiValueMap<String, Object> body
  = new LinkedMultiValueMap<>();
body.add("firstName", getFirstName());
body.add("images", getImage1());
body.add("images", getImage2());
body.add("lastName", getLastName());

HttpEntity<MultiValueMap<String, Object>> entityData
  = new HttpEntity<>(body, headers);

RestTemplate template = new RestTemplate();
ResponseEntity<String> response = template
  .postForEntity('endpoinit URL', entityData, String.class);  

感谢它为单文件工作如何发送多个jsonGood,@Ganesh Patil。请详细说明您试图返回的JSON多部分响应对象类型。我想发送一些数据,如名字、姓氏和两张图片file@GaneshPatil请仔细阅读更新后的回复。我必须发送一份包含多个文件和一些数据的回复,您可以查看
@GET
@Produces(MediaType.APPLICATION_OCTET_STREAM)
 public Response multipartTest() {
  File file = new File("C:\\Users\\ganesh\\img\\logo.png");
  return Response.ok(file, MediaType.APPLICATION_OCTET_STREAM)
      .header("Content-Disposition", "attachment; filename=\"" + file.getName() + "\"" ) 
      .build();
}
MultiValueMap<String, Object> body
  = new LinkedMultiValueMap<>();
body.add("firstName", getFirstName());
body.add("images", getImage1());
body.add("images", getImage2());
body.add("lastName", getLastName());

HttpEntity<MultiValueMap<String, Object>> entityData
  = new HttpEntity<>(body, headers);

RestTemplate template = new RestTemplate();
ResponseEntity<String> response = template
  .postForEntity('endpoinit URL', entityData, String.class);