Note that there are some explanatory texts on larger screens.

plurals
  1. POWicket ByteArrayResource only downloadable: can I let the browser handle the MIME type?
    primarykey
    data
    text
    <p>Current situation: in the Java code, I'm fetching documents with attachments from a CouchDB via the Ektorp library. Those documents are mapped into Java objects, all working fine. In order to make those attachments accessible in the browser, I'm instantiating a ByteArrayResource with the document attachment as a byte array, the content-type, and the filename:</p> <pre><code>private ByteArrayResource handleAttachment(String key, String cType) { ByteArrayResource res = null; AttachmentInputStream attIS = CouchDB.INSTANCE.getCouchDbConnector().getAttachment(doc.getId(), key); InputStream is = new BufferedInputStream(attIS); try { // Convert InputStream to byte[] with Apache commons-io byte[] bytes = IOUtils.toByteArray(is); attIS.close(); is.close(); res = new ByteArrayResource(cType, bytes, key); } catch (IOException e) { logger.error("", e); } return res; } </code></pre> <p>I'm then simply adding a ResourceLink to my page:</p> <pre><code>ByteArrayResource resource = handleAttachment(key, cType); add(new ResourceLink("resLink", resource)); </code></pre> <p>The problem is: when I'm clicking that link in a browser, all attachments are downloading, no matter what the content-type is. When I access those attachment from the CouchDB directly via the browser, an "image/xxx" content-type opens the image in the browser, "text/xxx" get's displayed in the browser, "and "application/pdf" is also handled by the browser (Safari e.g. displays the PDF immediately).</p> <p>How can I achieve that with Wicket? Any help is appreciated. Please keep in mind that I do not want shared resources, my site is secured. Thank you!</p> <p>PS: What's kind of interesting, if I open one of those "image" content-type ResourceLinks with the "rel="prettyPhoto" attribute, I get the JQuery PrettyPhoto plugin to correctly display that picture in a layover. The browser however triggers a download.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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