I'm developing a rest web service with Spring in Java that provides images to the front-end , which calls Java with an ajax event. On the server side I'm using Image from java.
import java.awt.Image;
I create an image based on another
Image img = bimg.getScaledInstance( width , height , BufferedImage.SCALE_SMOOTH );
BufferedImage buffer = toBufferedImage( img );
ByteArrayOutputStream bao = new ByteArrayOutputStream();
ImageIO.write( buffer , image.getMime( ) , bao );
String encoded = Base64.encodeBase64String( bao.toByteArray( ) );
Only the string encoded is always empty. The web service is developed with spring boot.
@RestController
public class ImageController {
...
@RequestMapping( value = "/" , method = RequestMethod.GET )
public ImageSearchResults getImages( @RequestParam(value="input", defaultValue="") String input) {
List< ImageResult > imageResults = getImageResults( input );
return new ImageSearchResults( imageResults );
}
}
getImageResult processes the request and builds the list of objects of type ImageResult that one of the attributes would be the image itself, as well as the height and length of the image.
Any idea how best to pass an image backend (web service) that is only in memory for the front-end (js)?