I have a csv file placed in dam , I want to write a groovy script to update the csv file with the new data,
the data I am able to fetch with the script only thing that is require is to push it into csv file
e.g : how to push "demo data " to csv file
Please help me out here, what could be the possible solution for this
Thank you
Solved! Go to Solution.
Views
Replies
Total Likes
@rahul234dabas
Use Asset API to get the binray data of csv, IO API will not work here.
Resource rs = resourceResolver.getResource(path); Asset asset = rs.adaptTo(Asset.class); // We have the inputstream InputStream data = asset.getOriginal().getStream();
Please check if this helps https://blogs.apache.org/groovy/entry/reading-and-writing-csv-files
@arunpatidar I am getting file not found error even when I have placed the file at the same place
:
filePath = "/content/dam/demo/output.csv";
File file = new File(filePath);
def rows = file.readLines().tail()*.split(','); // getting exception here as file not found exception
println "the file is : "+ rows;
The file is present in the location and is published also not sure why it's not picking it up
@rahul234dabas
Use Asset API to get the binray data of csv, IO API will not work here.
Resource rs = resourceResolver.getResource(path); Asset asset = rs.adaptTo(Asset.class); // We have the inputstream InputStream data = asset.getOriginal().getStream();
@arunpatidar thank you for the solution , I am now able to access the file in dam , I want to update data with my script in the mentioned file , can you tell me how to do it?
thank you
To update the asset binary you need to use below method