Hi,
I have uploaded a CSV file using DMS from vFlow. Now I want to read the uploaded csv in Java code.
Could anyone show me the code snippet or proper way of doing this?
Hi,
I have uploaded a CSV file using DMS from vFlow. Now I want to read the uploaded csv in Java code.
Could anyone show me the code snippet or proper way of doing this?
Step1: Download file from DMS by below API:
curl --location 'https://YOUR-VRT-SERVER-URL/document-manager/download/v1/getDocumentsUsingIds' \
--header 'storageid: STORAGE_ID' \
--header 'appid: VAHANA_APP_ID' \
--header 'requestid: UNIQUE_REQUEST_ID' \
--header 'orgid: VAHANA_ORG_ID' \
--header 'Content-Type: application/json' \
--data '{
"fileReturnType": "URL",
"expiryTime": 60,
"idList": [
"FILE_ID"
]
}'
Step2: Below is java code to read csv file:
public class ReadLargeCsvFile {
static String COMMA = ",";
static String path = "employee.csv";
public static void main(String[] args) {
processCSVFile(path);
}
private static void processCSVFile(String filePath) {
try (InputStream inputStream = Files.newInputStream(new File(filePath).toPath());
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));) {
// skip the header of the csv
bufferedReader.lines().skip(1).map(ReadLargeCsvFile::mapToEmployee)
.forEach(e -> {
//Write your logic here to process the record
System.out.println(e);
});
} catch (IOException e) {
e.printStackTrace();
}
}
private static Employee mapToEmployee(String line) {
String[] p = line.split(COMMA);
Employee e = new Employee();
e.setFirstName(p[0]);
e.setLastName(p[1]);
e.setGender(p[2]);
e.setAddress(p[3]);
return e;
}
Welcome to the community @naveen.gupta.
Thanks for the answer. It will solve the purpose.
One little question, Do we need CURL or can call this from JAVA itself?
Also be aware that this is a public forum and we should avoid exposing ID’s and other private info to the forum (have done that for you for now ).
It will help a lot.
@vinay.mahipal This is solution you were asking right?
@DebugHorror I will make a note on the private info.
Yes, We can create a vConnect Service and call it from Java to download file from DMS.