I m trying to send a csv file in post request and want to get the csv data at server.I am using jersey for creating web service.what should be the content type while sending csv file and what should be @consumes(__) annotation at server side
Please help
jersey code
@POST
@Consumes("text/plain")
@Produces("text/plain")
public String respondToPost(String incomingCsv) throws IOException {
return incomingCsv;
}
csv file :
email,group_email
member1@visheshapps.uni.me,team3@visheshapps.uni.me
member2@visheshapps.uni.me,team3@visheshapps.uni.me
this returns :
----0246824681357ACXZabcxyz
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: <startpart>
Content-Disposition: form-data; name="root-fields"
----0246824681357ACXZabcxyz
Content-Type: application/vnd.ms-excel
Content-Transfer-Encoding: binary
Content-ID: <group.csv>
Content-Disposition: attachment; name="file attachment"; filename="group.csv"
email,group_email
member1@visheshapps.uni.me,team3@visheshapps.uni.me
member2@visheshapps.uni.me,team3@visheshapps.uni.me
----0246824681357ACXZabcxyz--
while I want only
email,group_email
member1@visheshapps.uni.me,team3@visheshapps.uni.me
member2@visheshapps.uni.me,team3@visheshapps.uni.me
I changed the code but now I m getting 415 unsupported media type.my app is hosted on google app engine
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("text/plain")
public String respondToPost(@FormDataParam("file") InputStream csv) throws IOException {
CSVReader csvReader = new CSVReader(new InputStreamReader(csv));
List<String[]> rows = csvReader.readAll();
return rows.get(1)[0];
}
you could use
text\plainmediatype to recieve the request and OpenCSV to parse your request body.