why i can't generate the file in Adobe CQ | Community
Skip to main content
October 16, 2015
Solved

why i can't generate the file in Adobe CQ

  • October 16, 2015
  • 5 replies
  • 1180 views

Write a bundle and Jsp page call the function, it's weired that can't generate and find the file.

@Override public String generateFileTest() { File file = new File("test.xml"); file.createNewFile(); return file.getAbsolutePath(); }

 

Anybody know the reason? BTW, if need to set configure in AEM?

Thanks in advance.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

When writing a method in AEM that works with a File - make sure that AEM can locate the file. Typically, a file is located in the DAM and you use an AEM API to get the file. For example, QueryBuilder API. Here is a community article that shows how to write functionality in AEM that works with files. In this example, the AEM functionality returns a collection of DAM graphic files. See:  

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

5 replies

smacdonald2008
Level 10
October 16, 2015

So in your use case - you are simply attempting to dynamically create a file and then you want to return the path? As i pointed out - most ppl working with files in AEM, read files from the DAM and return data. In that use case - you can write a query that gets the file, and then return the location of the file:

 String path = hit.getPath();

If you create a File and return the path using this method: getAbsolutePath:

Returns the absolute pathname string of this abstract pathname.

This API call inside an AEM service may not resolve to the JCR location. I would use AEM APIs to get the JCR path of a digital asset (ie -a file in AEM). For example - QueryBuilder API.  Or you can use JCR API. 

Likewise , you can write files to AEM. For example - a client libs location. Read this community as an example:

http://helpx.adobe.com/experience-manager/using/post_files.html

This handles files that  a client app posts to AEM. So in AEM - you can create services that read and write files to AEM.  Use AEM APIS not the File API. 

October 16, 2015

Yes, this code run fine and no exception. But always can't find the generate file.

October 16, 2015

You can find your file by path <path_to_your_cq>\crx-quickstart\test.xml

To see and use this file in CQ you can save it to a node with a type "nt:resource" to property with name "jcr:data"

Adobe Employee
October 16, 2015

What exactly isn't working? This code should run fine on AEM.

smacdonald2008
smacdonald2008Accepted solution
Level 10
October 16, 2015

When writing a method in AEM that works with a File - make sure that AEM can locate the file. Typically, a file is located in the DAM and you use an AEM API to get the file. For example, QueryBuilder API. Here is a community article that shows how to write functionality in AEM that works with files. In this example, the AEM functionality returns a collection of DAM graphic files. See:  

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