2017-03-28 3 views
0

내 Playframework 2.5.0 응용 프로그램은 임시로 생성 된 zip 파일을 제공해야합니다. /tmp 디렉토리의 zip 파일을 아무 문제없이 작성하고 실행합니다 (이 위치에서 열어 포함 된 파일을 추출 할 수 있음).Playframework 2.5.0 : 서버 쪽 생성 된 zip 파일을 제공 할 수 없습니다.

그러나 클라이언트로 보낸 파일이 잘 리면 열릴 수 없습니다.

String tempPath = "/tmp/" + label + ".zip"; 

File zipFile = new File(tempPath); 
zipFile.deleteOnExit(); 
ZipOutputStream zos = null; 

try { 
    zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile))); 

    for (/* loops through files to zip */) { 
     InputStream is = methodToGetTheDocument(); 
     ZipEntry zipEntry = new ZipEntry(document.getLabel()); 
     zos.putNextEntry(zipEntry); 
     byte[] bytes = new byte[2048]; 
     int count = is.read(bytes); 
     while (count > -1) { 
      zos.write(bytes, 0, count); 
      count = is.read(bytes); 
     } 
     is.close(); 
     zos.closeEntry(); 
    } 
    return ok(zipFile); 
} catch (Exception e) { 
    return badRequest("Bad request"); 
} finally { 
    try { 
     zos.close(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

고전적인 결과 개체를 반환합니다 ... 무엇이 문제입니까?

+0

zip 파일을 변경하지 않는 경우, 왜 그냥 '확인 (새 java.io.File의를 반환하기 전에 zos.close()를 사용해야합니다 ("/ 경로 /로/7file.zip "));'? – Salem

답변

2

당신은 "가까운"zip 파일은 return ok(zipFile)

관련 문제