Reputation: 2045
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
[email protected],[email protected]
[email protected],[email protected]
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
[email protected],[email protected]
[email protected],[email protected]
----0246824681357ACXZabcxyz--
while I want only
email,group_email
[email protected],[email protected]
[email protected],[email protected]
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];
}
Upvotes: 1
Views: 8528
Reputation: 4693
you could use text\plain
mediatype to recieve the request and OpenCSV to parse your request body.
Upvotes: 1