I wrote a Restful webservice with MongoDB. This is my code :
@GET
@Path("/download/{id}/")
@Produces("application/epub")
public Response getImagefile(@PathParam("content") String content,
@PathParam("id") String imageID) throws UnknownHostException, IOException {
String urlContent = "D:\\NetbeansWorkspace\\Webservice\\web\\download\\image.jpg";
GridFSDBFile findImage;
DB db = getConnection().getDB(content);
GridFS gfsImage = new GridFS(db, "image");
findImage = gfsImage.findOne(new ObjectId(imageID));
findImage.writeTo(urlContent);
File file = new File(urlContent);
ResponseBuilder response = Response.ok((Object) urlContent);
response.header("Content-Disposition",
"attachment; filename=" + "image.jpg");
return response.build();
}
I am extracting an image from a server and providing a link to it for a download. This code does this not very efficiently by saving it to urlContent (my local file) first and then making it available for download. I would like to skip saving to urlContent part and provide a link which extracts and downloads a blob image directly from the server. How can I do it?