Hi,
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 .
Thanks
Isha
Hi,
You can use ContentReader service read content of file.
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("java.io.tmpdir")); tempCSVFile = File.createTempFile(csvFileName, tempDir); final ContentReader reader = contentService.getReader(csvNodeRef, ContentModel.PROP_CONTENT); if (reader.getSize() > 0) { reader.getContent(tempCSVFile); } //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()) { tempCSVFile.delete(); } }
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.