how to read CSV file from alfresco repository

Showing results for 
Search instead for 
Did you mean: 
Member II

how to read CSV file from alfresco repository


I have stored CSV file in repository using bulk import .Now I want to read that CSV file in my java class .Also I have noderef of the particular CSV file.

Kindly suggest API's/Sample code to read CSV file in alfresco .



2 Replies

Re: how to read CSV file from alfresco repository


Re: how to read CSV file from alfresco repository

Hi @Isha 

Use NodeService (NodeService Docs) to double check the node existance and get the name of csv file for creating a temp file which you will use during the processig of your program and at the end delete the temp csv file.

Use ContentService (ContentSerice Docs) to get the instance of ContentReader (as mentioned by Sanjay) for the csv nodeRef.


Pseudo Code:

File tempCSVFile = null;
try {
	if (csvNodeRef != null && nodeService.exists(csvNodeRef)) {
	    final String csvFileName = (String) nodeService.getProperty(csvNodeRef, ContentModel.PROP_NAME); //get the file name from node.

		//create temp file in temp directory
		final File tempDir = new File(System.getProperty(""));
		tempCSVFile = File.createTempFile(csvFileName, tempDir);
		final ContentReader reader = contentService.getReader(csvNodeRef, ContentModel.PROP_CONTENT);
		if (reader.getSize() > 0) {
		//Now you have csv temp file, you can read it as file input stream and process the stream
		final InputStream inStreamJson = Files.newInputStream(Paths.get(tempCSVFile));
		//Process the stream as needed.
} catch(InvalidNodeRefException | ContentIOException nodeEx) {
  //log error appropriately 
} catch(AlfrescoRuntimeException alfEx) {
  //log error appropriately 
} catch(RuntimeException runEx) {
  //log error appropriately 
} catch(Exception excp) {
  //log error appropriately 
} finally {//delete temp csv file.
	if (tempCSVFile != null && tempCSVFile.exists()) {



(ACSCE, AWS SAA, Azure Admin)