FileDownload

Methods

 

 

startStreamDownload

스트림 다운로드를 시작합니다.

 

Syntax

    void startStreamDownload ( InputStream inputStream, String fileNameAlias, long fileSize, boolean attachment )

Parameters

inputStream

[in] 다운로드 할 InputStream 객체를 입력합니다.

fileNameAlias

[in] 클라이언트 컴퓨터에 저장될 파일 이름(별칭)을 입력합니다. 영문이 아닐 경우, 웹서버 환경에 따라 적절히 인코딩 되어야 합니다.

fileSize

[in] 다운로드 할 InputStream 객체의 크기를 입력합니다.

attachment

[in] 파일의 종류에 관계 없이 항상 파일로 저장할 수 있도록 설정합니다. 기본 값은 false입니다.

true

파일의 종류에 관계 없이 항상 파일로 저장합니다.

false

파일 종류 및 클라이언트 컴퓨터의 환경에 따라 파일이 웹브라우저에서 열릴 수 있습니다.

 

Return Values

 

Remarks

 

Sample Codes

Java

FileDownload fileDownload = new FileDownload(request, response); 
Connection con = null; 
PreparedStatement pstmt = null;
ResultSet rs = null; 
InputStream fis = null; 

try { 
	// 테스트를 위해 session 객체에 저장해 놓은 DB의 id 컬럼 값을 가져온다.   
	String id = session.getAttribute("id").toString(); 

	String user = "USER"; 
	String password = "PASSWORD"; 
	//Class.forName("org.gjt.mm.mysql.Driver");
	Class.forName("com.mysql.jdbc.Driver").newInstance();  
	con = DriverManager.getConnection("jdbc:mysql://localhost:3306/blob_db", user, password);

	String query = "SELECT id, filename, filedata FROM blob_table WHERE id =" + id; 
	pstmt = con.prepareStatement(query); 

	pstmt.clearParameters();
	rs = pstmt.executeQuery();

	if (rs != null && rs.next()) {
		String filename = rs.getString("filename");
		Blob filedata = rs.getBlob("filedata");
		fis = filedata.getBinaryStream();
		
		// fileNameAlias는 웹서버 환경에 따라 적절히 인코딩 되어야 합니다.
		String fileNameAlias = URLEncoder.encode(filename, "UTF-8"); 
		long fileSize = filedata.length();  
		boolean attachment = false; 
		// f스트림 다운로드를 시작합니다. 
		fileDownload.startStreamDownload(fis, fileNameAlias, fileSize, attachment); 
	}
}
catch(CrossUploaderException ex) {  
	System.out.println("다운로드 중 예외 발생 : " + ex.getMessage()); 	
}
catch(Exception ex) { 
	System.out.println("다운로드 중 예외 발생 : " + ex.getMessage()); 	
}
finally { 
	// DB 연결 종료
	if(fis != null)
		fis.close(); 
	if(rs != null)
		rs.close();
	if(pstmt != null)
		pstmt.close(); 
	if(con != null)
		con.close(); 	
}