Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

Downloading image from jcr:data


Level 2

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;


    jcrDataProperty = jcrDataNode.getProperty(JcrConstants.JCR_DATA);

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

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



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


    String fileName = getFileName(fileNode,mimeType);


    fileName = CommonUtil.truncateFileName(fileName);


    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);



0 Replies