Create CSV file programmatically as DAM asset | Community
Skip to main content
Level 3
Feb 27, 2018 5:48 AM UTC
Solved

Create CSV file programmatically as DAM asset

Hi All,

I am working on a requirement where we need to create a CSV file from SQL database and save the file in DAM location. In order to create the CSV file in DAM location I am unsing AssetManager.createAsset("/content/dam/../..test.csv", is, "text/csv", true).

The issue that I am facing here is inorder to create asset we need an InputStream object, so I am first creating a File object and then using CSVWriter to create a CSV in another location and then converting that File object to InputStream like this ::InputStream is = new FileInputStream(csvFile);

Can someone please suggest me an approach where I can create the CSV file directly in DAM location.

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
Feb 27, 2018 2:48 PM UTC

Create an AEM Java service that creates a CSV file and then use the Asset Manager API or JCR NODE API to place the asset into the DAM location. Java CSV - java code samples

7 replies

saurabhn3378167
New Participant
Oct 25, 2021 5:41 PM UTC

I am facing same issue. looks like there is no direct way to convert file writer to input stream.. as AssetManager.createAsset() method takes inputstream as parameter so first we need to create file from csvwriter and again read that file via inputstream and pass it to AssetManagerAPI to place it on DAM.

Translate
smacdonald2008
smacdonald2008Accepted solution
Level 10
Feb 27, 2018 2:48 PM UTC

Create an AEM Java service that creates a CSV file and then use the Asset Manager API or JCR NODE API to place the asset into the DAM location. Java CSV - java code samples

Translate
Hemant_arora
Level 8
Feb 27, 2018 9:45 AM UTC

See this example to create CSV. Change the query according to your requirement if you want users, assets or pages to be exported in csv. https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/master/bundle/src/main/java/com/adobe/acs/commons/exporters/impl/users/UsersExportServlet.java

Translate
Hemant_arora
Level 8
Feb 27, 2018 7:33 AM UTC

You can find so many examples to create csv and for uploading to dam refer to the last servlet part in this example https://helpx.adobe.com/experience-manager/using/uploading-files-aem1.html

Translate
Level 3
Feb 27, 2018 6:40 AM UTC

Thanks for the reply. I have checked this, but this is slightly different from my requirement, I just want to create a .csv file programmatically  and place it in DAM. This file will then be pushed to another server to other uses.

Translate
Level 2
Apr 1, 2021 5:53 PM UTC
@smrithi_govind , I'm working on similar requirement. Facing the same issue as yours. Did you find any solution to this?
Translate
Hemant_arora
Level 8
Feb 27, 2018 6:04 AM UTC