Highlighted

Downloading image from jcr:data

varung44569684

27-03-2018

Hi Team ,

Can you please suggest me what is the best way to download image from jcr:Data which has been uploaded to page itself and not DAM,

I am using below code to download the image but the image pixels are not proper in some cases and some of the image cut.

     private static final int BUFSIZE = 10240;

     if(jcrDataNode.hasProperty(JcrConstants.JCR_DATA)){

    jcrDataProperty = jcrDataNode.getProperty(JcrConstants.JCR_DATA);

    inStream = jcrDataProperty.getBinary().getStream();

    contentSize = jcrDataProperty.getBinary().getSize();

    }

    if(jcrDataNode.hasProperty(JcrConstants.JCR_MIMETYPE)){

    mimeType = jcrDataNode.getProperty(JcrConstants.JCR_MIMETYPE).getString();

    }

    String fileName = getFileName(fileNode,mimeType);

  

    fileName = CommonUtil.truncateFileName(fileName);

    if(inStream!=null){

    setResponseAttributes(response, mimeType, contentSize.toString(), fileName);

    byte[] buffer = new byte[BUFSIZE];

    int length;

    inputStream = new BufferedInputStream(inStream, BUFSIZE);

    outStream = new BufferedOutputStream(response.getOutputStream(), BUFSIZE);

  

    // reads the file's bytes and writes them to the response stream

        while ((length = inputStream.read(buffer)) > 0) {

            outStream.write(buffer, 0, length);

        }

    }