Attach pdf with email

Avatar

Avatar
Validate 10
Level 2
sumitc22
Level 2

Likes

4 likes

Total Posts

71 posts

Correct reply

3 solutions
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Affirm 3
View profile

Avatar
Validate 10
Level 2
sumitc22
Level 2

Likes

4 likes

Total Posts

71 posts

Correct reply

3 solutions
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Affirm 3
View profile
sumitc22
Level 2

13-11-2015

   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 ?

 

View Entire Topic

Avatar

Avatar
Validate 10
Level 1
vishalv75424481
Level 1

Likes

0 likes

Total Posts

26 posts

Correct reply

0 solutions
Top badges earned
Validate 10
Validate 1
View profile

Avatar
Validate 10
Level 1
vishalv75424481
Level 1

Likes

0 likes

Total Posts

26 posts

Correct reply

0 solutions
Top badges earned
Validate 10
Validate 1
View profile
vishalv75424481
Level 1

13-11-2015

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