Expand my Community achievements bar.

SOLVED

CSV file upload and populating data in a table

Avatar

Community Advisor

Hi,

 

I have a requirement of fetching data from a CSV file and rendering it in a table on a page. 

A high level approach that I have thought of is:

1. Author uploads the CSV file in DAM.

2. We create a component which has fileupload option.

3. Author adds the component on a page. Author Drags and Drops the CSV file in the component dialog.

4. Using sling model we fetch the data from CSV and we use sightly to render it the page.

 

Can you please suggest me other approaches that I can consider or any tools or utilities that are already in place to be used?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @ksh_ingole7 

 

I think you can remove file upload option at component level as the file is already present in DAM and you can read it from the DAM directly, so you can just achieve your requirement with below steps: 

 

1. Author uploads the CSV file in DAM 

2. Create component with required dialog fields other than file upload (Why do you want to add extra step here for author to upload or drag & drop the CSV file which is already present in DAM?  is there any reason for this?)

3. Sling Model to read the CSV file from DAM and render it on the page.

 

Note: Just make sure to publish CSV file from DAM every time there is a change.

 

Thanks

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @ksh_ingole7 

 

I think you can remove file upload option at component level as the file is already present in DAM and you can read it from the DAM directly, so you can just achieve your requirement with below steps: 

 

1. Author uploads the CSV file in DAM 

2. Create component with required dialog fields other than file upload (Why do you want to add extra step here for author to upload or drag & drop the CSV file which is already present in DAM?  is there any reason for this?)

3. Sling Model to read the CSV file from DAM and render it on the page.

 

Note: Just make sure to publish CSV file from DAM every time there is a change.

 

Thanks

Avatar

Community Advisor

@ksh_ingole7,

1. Architect the best location in the DAM where the CSV files will live; create documentation and reference this location.

2. I suggest you to use a system user so you can access the CSV file from the dam from the sling model backend.

3. Assuming that maybe in the future there may be more uses of CSVtoHTML, you can create a utils class called CsvUtils.java, which will have some methods in there like converCSVStringToHtml(); http://www.java2s.com/example/java/java.lang/convert-a-csv-string-to-a-html-table-string-for-display...

4. Create the AEM component with a required pathField, rootPath property that points directly to the folder structure that was mentioned in #1. https://sourcedcode.com/blog/aem/aem-granite-ui-1-0-form-components-xml-reference-guide#granite-ui-p...

5. Create the AEM Sling Model that uses the System User to get access to the CSV file, open the file and obtain its contents; next pass the contents of the CSV to the CsvUtils.java class, which will output the table.