0
votes

I'm getting a PathNotFoundException in cq5 while accessing a node. I'm trying to extract the data of a pdf file from its jcr:content node. but i'm getting path not found exception because name of my file contains spaces because it sling not able to map the request to corresponding file. My file name is "Sbi FB Deals Done.pdf" which is getting converted by my code into /content/dam/sbi/personal/docs/Sbi%20FB%20Deals%20Done.pdf

due to %20its not getting map with file. here is my code where i'm getting this exception

Node fileNode = session.getNode(filePath+"/jcr:content/renditions/original/jcr:content");           
            inputStream = fileNode.getProperty("jcr:data").getBinary().getStream();

where file path is /content/dam/sbi/personal/docs/Sbi FB Deals Done.pdf

any idea for this ? any way to access a file who contains spaces in cq5

1
Did you try to keep the spaces when you load the node? And I would start just with the filePath and use the API to get to the renditions, there are already methods on the Asset class to get the stream. - Thomas
can you please explain that method i just want the stream of that file by giving my path - user2142786

1 Answers

0
votes

To be able to format code propery I post this as an answer. This is how I did it in a similar case, though I get the node from a search and I am using the ResourceResolver and Adaptable Interface from the Resource:

String filePath = "/content/dam/sbi/personal/docs/Sbi FB Deals Done.pdf";
InputStream fileStream = null;
try {
    Asset asset = resolver.resolve(filePath).adaptTo(Asset.class);
    fileStream = asset.getOriginal().getStream();
    //do whatever you need to do with the stream
} catch (IOException e) {
} finally {
    IOUtils.closeQuietly(fileStream);
}