Can any one please provide inputs on the same?
Solved! Go to Solution.
Views
Replies
Total Likes
@jhansi_123 I believe you have created custom component to render txt content - In that case please follow below steps.
Please refer below sample code which you may need to read txt from JCR.
File should have an nt:file node, which has a jcr:content node with jcr:data property.
You can read the xml from jcr:data i.e: jcrContent.getProperty("jcr:data").getBinary().getStream();/
InputStream is = jcrContent.getProperty("jcr:data").getBinary() .getStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayOutputStream buf = new ByteArrayOutputStream(); int resultNumber = bis.read(); while (resultNumber != -1) { byte b = (byte) resultNumber; buf.write(b); resultNumber = bis.read(); }
Hi @jhansi_123 ,
You can achieve this by "Apache Sling Content Disposition Filter" which controls Content Disposition for different mime types based on the path.
Please refer to the similar thread below which I recently posted the answer for pdf and similar approach for txt.
Hope that helps!
Regards,
Santosh
Hi Santhosh,
currently working on local only.
I have uploaded my .txt file under dam folder.
is there any other way to do it?
@jhansi_123 I believe you have created custom component to render txt content - In that case please follow below steps.
Please refer below sample code which you may need to read txt from JCR.
File should have an nt:file node, which has a jcr:content node with jcr:data property.
You can read the xml from jcr:data i.e: jcrContent.getProperty("jcr:data").getBinary().getStream();/
InputStream is = jcrContent.getProperty("jcr:data").getBinary() .getStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayOutputStream buf = new ByteArrayOutputStream(); int resultNumber = bis.read(); while (resultNumber != -1) { byte b = (byte) resultNumber; buf.write(b); resultNumber = bis.read(); }
Views
Likes
Replies
Views
Like
Replies