Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You may also want to consider streaming the images out to the browser rather than encoding them on the page itself.</p> <p>Here's an example of streaming an image contained in a file out to the browser via a servlet, which could easily be adopted to stream the contents of your BLOB, rather than a file:</p> <pre><code> public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { ServletOutputStream sos = resp.getOutputStream(); try { final String someImageName = req.getParameter(someKey); // encode the image path and write the resulting path to the response File imgFile = new File(someImageName); writeResponse(resp, sos, imgFile); } catch (URISyntaxException e) { throw new ServletException(e); } finally { sos.close(); } } private void writeResponse(HttpServletResponse resp, OutputStream out, File file) throws URISyntaxException, FileNotFoundException, IOException { // Get the MIME type of the file String mimeType = getServletContext().getMimeType(file.getAbsolutePath()); if (mimeType == null) { log.warn("Could not get MIME type of file: " + file.getAbsolutePath()); resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } resp.setContentType(mimeType); resp.setContentLength((int)file.length()); writeToFile(out, file); } private void writeToFile(OutputStream out, File file) throws FileNotFoundException, IOException { final int BUF_SIZE = 8192; // write the contents of the file to the output stream FileInputStream in = new FileInputStream(file); try { byte[] buf = new byte[BUF_SIZE]; for (int count = 0; (count = in.read(buf)) &gt;= 0;) { out.write(buf, 0, count); } } finally { in.close(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload