我正在尝试在 post 请求中发送 csv 文件,并希望在服务器上获取 csv 数据。我正在使用 jersey 来创建 Web 服务。发送 csv 文件时内容类型应该是什么,@consumes( __ ) 注释应该是什么在服务器端请帮助
球衣代码
@POST
@Consumes("text/plain")
@Produces("text/plain")
public String respondToPost(String incomingCsv) throws IOException {
return incomingCsv;
}
.csv 文件:
email,group_email
member1@visheshapps.uni.me,team3@visheshapps.uni.me
member2@visheshapps.uni.me,team3@visheshapps.uni.me
这返回:
----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--
而我只想
email,group_email
member1@visheshapps.uni.me,team3@visheshapps.uni.me
member2@visheshapps.uni.me,team3@visheshapps.uni.me
我更改了代码,但现在我得到了 415 不受支持的媒体类型。我的应用程序托管在谷歌应用程序引擎上
@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];
}