2014-06-06 2 views
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(); 
} 

질문

어떤 종류의 파일을 업로드하는 데 가장 유용한 두 가지 기능은 무엇입니까?

답변

0

멀리 떨어져있는 것이 가장 좋은 옵션은 서버 메모리에 전체 파일을로드하지 않고 웹을 통해 파일을 스트리밍하는 경우에만 스트리밍입니다. Enjoy :

관련 문제