Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Want to display particular file in page

Avatar

Level 3

Hi,

  My requirement is to uploaded file should be display in page when ever i want to display pdf,ppt,doc, it should be display on page after clicking particular file name,below code i have writen but by default it is taking last condition am unable to display pdf file if i give jcr:content : property as::application/pdf  then i can able to display pdf on page.

 


    ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
    session = resourceResolver.adaptTo(Session.class);     
    Node node = session.getNode("/x/y/z/assets");  
   //System.out.println(node.getpath());
    javax.jcr.ValueFactory valueFactory = session.getValueFactory();             
    javax.jcr.Binary contentValue = valueFactory.createBinary(is);            
    Node fileNode = node.addNode(fileName, "nt:file"); 
        fileNode.addMixin("mix:referenceable"); 
    Node resNode = fileNode.addNode("jcr:content", "nt:resource"); 
    //String fileupld = "image/jpeg";
    String fileupld = "application/x-mspowerpoint,application/x-compressed,application/excel,application/msword,application/pdf,text/plain,image/jpeg,";    

That will be great for you answer

1 Accepted Solution

Avatar

Correct answer by
Level 6

You can display this image of documents by using html img tag. Under a loop you can iterate all the uploaded documents and point the  SRC attribute to the location of the file.

View solution in original post

5 Replies

Avatar

Correct answer by
Level 6

You can display this image of documents by using html img tag. Under a loop you can iterate all the uploaded documents and point the  SRC attribute to the location of the file.

Avatar

Level 3

Thanks, 

 

 I have tried with your suggestion i gave loop condition pdf is displaying but coming to ppt and doc , it is displaying error as Refused to display:in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

Avatar

Level 6

Step1: Create a bin class which will hold the location of each document when any uploading documents.

bean.setDocumentPath(node.getPath());

Step 2: iterate this bin object in your jsp as follows - 

for(DocumentBean doc:docs){ 
%>
<a href="<%=doc.getDocumentPath()%>" target="_blank">
<img height="92" width="146" alt="Document" src='<%=doc.getImgUrl()%>'>
</a>
 

doc.getDocumentPath() should return the location : /content/mysite/somedoc.pdf

 

Hope it helps!

Avatar

Level 6

Please mark it as resolved if it helps!