//----------------------------------------------------
//파일 폼 데이터 스레드
//----------------------------------------------------
private class AsyncFileThread extends Thread {
String address;
File file;
public AsyncFileThread(String addr, File _file){
address = addr;
file = _file;
}
public void run(){
httpclient = new DefaultHttpClient();
try {
HttpPost post = new HttpPost(address);
//헤더 설정
post.setHeader("Connection", "Keep-Alive");
post.setHeader("Accept-Charset", "UTF-8");
post.setHeader("ENCTYPE", "multipart/form-data");
//멀티파트 엔티티 생성, 파일 이름이 한글일 경우 Charset을 정하는 게 좋음
MultipartEntity multipartContent =
new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE,
null, Charset.forName("UTF-8"));
//파일 붙임
FileBody cbFile = new FileBody(file);
multipartContent.addPart("file1", cbFile);
//파라메터
for(NameValuePair nvp:nameValues){
multipartContent.addPart(nvp.getName(),
new StringBody(URLEncoder.encode(nvp.getValue(), HTTP.UTF_8)));
}
//파일 사이즈
multipartContent.addPart("fileSize", new StringBody(String.valueOf(file.length())));
//HttpPost Entity에 연결
post.setEntity(multipartContent);