0
정보
은 현재 내가 업로드하는 두 가지 방법이 저지와 파일 (요청) : 응답 방법 1 개 반환을저지로 (요청 된) 파일을 업로드하는 가장 좋은 방법은 무엇입니까?
- 방법이 수익을 StreaminOutput
- 을
@GET
@Path("download-file1/{fileName}")
public StreamingOutput downloadFile1(@PathParam("fileName") final String fileName)
throws FileNotFoundException {
final File file = new File("path/to/my/dir/" + fileName);
if (!file.exists()) {
throw new FileNotFoundException;
}
return new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
Files.copy(file, output);
}
};
}
@GET
@Path("download-file2/{fileName}")
public Response downloadFile2(@PathParam("fileName") final String fileName) throws FileNotFoundException{
final File file = new File("path/to/my/dir/" + fileName);
if (!file.exists()) {
throw new FileNotFoundException;
}
ResponseBuilder rb = null;
rb = Response.ok((java.lang.Object)file);
rb.header("Content-Disposition", "attachment; filename=" + fileName);
return rb.build();
}
질문
어떤 종류의 파일을 업로드하는 데 가장 유용한 두 가지 기능은 무엇입니까?