我在我的項目中使用球衣API。我堅持要求下載文件的案例,但事實並非如此。我的代碼如下文件沒有得到下載使用JERSEY
@GET
@Produces("application/download")
public Response downloadFile(){
String data = getDatas();
ResponseBuilder response = Response.ok(data);
response.header("Content-Disposition","attachment;filename=UserData.txt");
response.header("charset", "UTF-8");
return Response.build();
}
我已經添加了所有的包,路徑也很好。沒有錯誤來了。
當我調用這個API時,數據進入響應。我希望這些數據在文件中並且是可下載的格式。
我也試過@Produces(MediaType.APPLICATION_OCTET_STREAM)
。
請糾正我,如果我做錯
可能重複,http://stackoverflow.com/questions/12239868/whats-the-correct-way-to-send-a -file-from-rest-web-service-to-client – svarog