Skip to main content
Level 4
Nov 13, 2015 1:01 PM UTC
Solved

Attach pdf with email

   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 ?

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
smacdonald2008
smacdonald2008Accepted solution
Level 10
Nov 13, 2015 2:39 PM UTC

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.

4 replies

smacdonald2008
smacdonald2008Accepted solution
Level 10
Nov 13, 2015 2:39 PM UTC

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.

Translate
Level 2
Nov 13, 2015 7:56 PM UTC

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();
Translate
edubey
Level 10
Nov 14, 2015 10:10 AM UTC

Take a @ http://www.tothenew.com/blog/send-email-and-attach-filesimages-from-aem/ it shows how you can attach DAM files in email  

Translate
sumitc22Author
Level 4
Nov 15, 2015 3:13 AM UTC

Thanks All for your reply.

Getting the InputStream from asset worked.

Translate