according to this tutorial Base64 download REST web service I am trying to download from my client app, multiple images stored in a byte array who are send from my REST service. The REST resource file contains:
//****RESTful Service****
@GET // HTTP GET request
@Path("get_pictures/{userid}")
@Produces( MediaType.APPLICATION_OCTET_STREAM )
// Gets all the pictures for the report
public Response getReportPictures(@PathParam("userid") int userid) {
return wsmanager.getReportPictures(userid);
}
In the below getReportPicture() method I am serializing the images and store them in an ArrayList which I want to return via the above REST service. The Image class is one of my libs to serialize and unserialize pictures. The serializing process and returning the ArraList of byte[] works well.
//**** getReportPicture() method *****
ArrayList<byte[]> pictures = new ArrayList<byte[]>();
...
Response response = null;
...
byte[] img = Image.serialize(strPictureFile);
pictures.add(img);
...
ResponseBuilder builder = Response
.ok( pictures, "image/jpg" )
.header( "Content-Disposition","inline; filename = \"" + name + "\"" );
response = builder.build();
return response;
At my Java client I am trying to read the content from the REST service, which is not working implementing the below code:
WebTarget target = baseTarget.path("get_pictures/"+userid);
Response clResponse = target
.request(MediaType.APPLICATION_OCTET_STREAM)
.get();
String s = clResponse.readEntity(String.class);
Can someone help please?.