[英]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.