I've a requirement in reading two uploaded text/csv files separately using REST ws(Jersey), below a sample snippet that depicts the same.
@Path("bcmfileinput")
public class BCMFileInputCheckResource{
@POST
@Path("survivour1")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
public String getSurvivour1File(@FormDataParam(value="eaiTradesFile")InputStream eaiTradesStream,@FormDataParam(value="outsandingFile")InputStream outTradesStream) throws IOException{
//writing eaiTradesStream to the file to test
BufferedReader br = new BufferedReader(new InputStreamReader(eaiTradesStream,"UTF-8"));
PrintWriter f=new PrintWriter(new File("H:/abc.csv"));
String line="";
while((line=br.readLine())!=null ){
f.write(line);
f.println();
}
f.flush();
f.close();
return "H:/abc.csv";
}
And a sample html page:
<html>
<body>
<h2>BCM File Upload</h2>
<form action="http://localhost:9080/swiftmx/public/bcmfileinput/survivour1" method="post" enctype="multipart/form-data">
<p>
Select Eai Positions file : <input type="file" name="eaiTradesFile" size="45" />
<br>
<br>
Select Outstanding file : <input type="file" name="outsandingFile" size="45" />
</p>
<input type="submit" value="Upload It" />
</form>
</body>
</html>
With the above code, when i write any one of stream to the file then both the files data being printed. But, my requirement is need to bind eaiTradesFile to 1st inputstream and outsandingFile file to 2nd inputstream as I've to process them separately for each file.
Been googling failed to find right solution for my requirement. So, any solution is appreciable for the same, Thank all in advance!!!