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

SOLVED

Attach pdf with email

sumitc22
Level 4
Level 4

   Hi,

We are trying to send a pdf attachment ( the file is stored in dam ) . The below mentioned code is used to read the file from DAM.         

 

   String fileName = "/content/dam/pdfs/retail/test.pdf";

                resource = resolver.getResource(fileName);

                Node imageNode = resource.adaptTo(Node.class);

                Node contentNode = imageNode.getNode("jcr:content");

                Binary contentBinary = contentNode.getProperty("jcr:data")

                        .getBinary();

              

        InputStream pStredfam = contentBinary .getStream()

-----------------------------------------------------------------------------------------

ByteArrayDataSource pdfDS = new ByteArrayDataSource(pdfStream,"application/pdf");

email.attach(pdfDS,"Some test","Some test");

---------------------------------------------------------------------------------------------------------------------------------

However , getting an error saying that "jcr:data" not found.

 

javax.jcr.PathNotFoundException: jcr:data not found on /content/dam/pdfs/retail/test.pdf/jcr:content

Can you please suggest what is the right way to do the same ?

 

1 Accepted Solution
smacdonald2008
Correct answer by
Level 10
Level 10

See this AEM community article where we read assets from the DAM and convert them to InputStreams.

https://helpx.adobe.com/experience-manager/using/downloading-dam-assets.html

This is what you should implement for your use case.

View solution in original post

4 Replies
smacdonald2008
Correct answer by
Level 10
Level 10

See this AEM community article where we read assets from the DAM and convert them to InputStreams.

https://helpx.adobe.com/experience-manager/using/downloading-dam-assets.html

This is what you should implement for your use case.

View solution in original post

vishalv75424481
Level 2
Level 2

Hi,

Is "/content/dam/pdfs/retail/test.pdf/jcr:content" the right location for jcr:data?

I think you have to give the path to a rendition (Original), which has the property "jcr:data". 

Try using this path instead - "/content/dam/pdfs/retail/test.pdf/jcr:content/renditions/original/jcr:content"

OR

you can try something like this - 

Resource rs = resourceResolver.getResource(path);
Asset asset = rs.adaptTo(Asset.class);  
InputStream data = asset.getOriginal().getStream();
sumitc22
Level 4
Level 4

Thanks All for your reply.

Getting the InputStream from asset worked.