简体   繁体   English

使用http'POST'从服务器端发送多个文件-发送FileInputStream的ArrayList

[英]Sending several files from server side using http 'POST' -send ArrayList of FileInputStream

I succesfully wrote an http 'post' that gets 1 file (image) from the server side like this: 我成功地写了一个http'post',它从服务器端获取了1个文件(图像),如下所示:

@Path("getImage")
@POST @Produces({MediaType.APPLICATION_OCTET_STREAM})
public Response getImage(picRequest request)  throws Exception {
     File file = ......
       return Response.ok(new FileInputStream(file)).build();
}

And I check it using client: 我使用客户端检查它:

ClientResponse response = webResource
            .type(MediaType.APPLICATION_JSON)
            .accept(MediaType.APPLICATION_OCTET_STREAM)
            .post(ClientResponse.class, inp);

The problem is that I cann't succeed when trying to send several files in a list. 问题是尝试发送列表中的多个文件时我无法成功。 (ArrayList of FileInputStream) (FileInputStream的ArrayList)

ArrayList<InputStream> resultData = new  ArrayList<InputStream>();
while (rs.next()) {
    ....
    resultData.add(new FileInputStream(file));
}
  return Response.ok(resultData).build();

How do I do it? 我该怎么做? and what should be the MediaType? MediaType应该是什么?

Thank you so much for helping. 非常感谢您的帮助。

Consider returning a multipart/mixed response. 考虑返回多部分/混合响应。 Here is an blog describing how to do this with Jersey specifically. 这是一个博客,专门描述如何使用Jersey。

http://geekoolympics.blogspot.com/2013/02/jersey-mutipart-resource-that-produces.html http://geekoolympics.blogspot.com/2013/02/jersey-mutipart-resource-that-produces.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发送一个 ArrayList<String> 使用套接字通过 TCP 从服务器端到客户端? - Sending an ArrayList<String> from the server side to the client side over TCP using socket? 使用TCP over socket将ArrayList从服务器端发送到客户端 - Sending ArrayList from server side to client side using TCP over socket 如何从服务器端获取post方法的http.send()参数? - How to get the parameter of http.send() for post method from the server side? Java服务器端:发送Http POST响应-仅状态 - Java Server Side: send Http POST response - status only 使用 POST 请求将值从 HTTP 客户端发送到 HTTP 服务器,用 Java 编码 - Sending a value from an HTTP client to an HTTP server using POST request, coding in Java 无法使用Java将POST请求中的ArrayList发送到REST服务器 - Not able to send an ArrayList in a POST request to the REST server using Java 如何在服务器端使用 java 从客户端的 HTTP POST 请求中接收和解析 JSON 对象 - How to receive and parse a JSON object from a HTTP POST request from client using java on the server side 使用HTTP发布方法将数据从android应用发送到phpMyAdmin服务器 - Sending data from android app to a phpMyAdmin server using HTTP post method 使用rest服务将文件从服务器端发送到客户端 - send a file from the server side to the client side using rest service 如何使用HTTP POST从Java应用程序发送XML并在服务器上使用PHP打印它? - How can I send XML from a Java application and print it with PHP on the server, using HTTP POST?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM