Hi I'm coding servlet to upload image as inputstream
under an object with static inputream.
After images uploaded, I am using some method to resize the image and return the resized image to the client.
My code work for the first time and after that the inputstrem is closed(i don't know exactly what this means and I can't read from it.
I have used several methods but still having the same problem
How to resolve this?
public String getImageArtRes() throws IOException {
ImageInputStream origimg =
ImageIO.createImageInputStream(this.get_Image());
BufferedImage img = ImageIO.read(origimg);
img.flush();
BufferedImage resized = resize(img, 80, 120);
String b64 = null;
resized.flush();
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(resized, this.getImgType().replace("image/", ""), os);
os.flush();
byte[] imageInByteArray = os.toByteArray();
b64 = javax.xml.bind.DatatypeConverter.printBase64Binary(imageInByteArray);
os.close();
return b64;
}
I am getting image with this code:
private static List<ArticleIMG> getImages(HttpServletRequest request) throws IOException, ServletException {
Collection<Part> parts = request.getParts();
InputStream img = null;
...
for (Part part : parts) {
...
img=part.getInputStream();
imgTemp.setImage(img);
getImagesArt().add(imgTemp);
...
My java version is 1.8