Expand my Community achievements bar.

SOLVED

why i can't generate the file in Adobe CQ

Avatar

Former Community Member

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.

1 Accepted Solution

Avatar

Correct answer by
Level 10

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

View solution in original post

5 Replies

Avatar

Correct answer by
Level 10

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

Avatar

Employee

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

Avatar

Level 1

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"

Avatar

Former Community Member

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

Avatar

Level 10

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.