Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Downloading image from jcr:data

Avatar

Avatar
Validate 10
Level 2
varung44569684
Level 2

Likes

2 likes

Total Posts

22 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Boost 1
View profile

Avatar
Validate 10
Level 2
varung44569684
Level 2

Likes

2 likes

Total Posts

22 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Boost 1
View profile
varung44569684
Level 2

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

        }

    }