안녕하세요?

multipart  post 방식으로 이미지 파일 업로드 하려고 하는데

디버깅 하면 아래 빨간 부분에서 계속 에러가 나네요...

이틀째 삽질하고 있는데 원인이 무엇인지 아시는분 부탁좀 드리겠습니다 ㅠㅠ



public boolean requestUpload(UploadDataItem item) throws IOException, JSONException {
String charset = "UTF-8";
String server = "http://hohoho-cloud.appspot.com"; 
String did = OfficeFolderManager.getInstance().getConnectionInfo().getSelectNode();
String token = OfficeFolderManager.getInstance().getConnectionInfo().getToken();
String filePath = item.getData();
String fileName = item.getName();

server = OfficeFolderManager.getInstance().getConnectionInfo().uploadRequstUrl();
String lineEnd = "\r\n\r\n";
StringBuilder body = new StringBuilder();
body.append("\r\n--" + BOUNDARY + "\r\n");
body.append("Content-Disposition: form-data; name=\"target_dir\""+lineEnd);
body.append(did);
body.append("\r\n--" + BOUNDARY + "\r\n");
body.append("Content-Disposition: form-data; name=\"token\""+lineEnd);
body.append(token);
body.append("\r\n--" + BOUNDARY + "\r\n");
body.append("Content-Disposition: form-data; name=\"created\""+lineEnd);
body.append("\r\n" + BOUNDARY + "\r\n");
body.append("Content-Disposition: form-data; name=\"modified\""+lineEnd);
body.append("\r\n--" + BOUNDARY + "\r\n");
body.append("Content-Disposition: form-data; name=\"file\"; filename=\"");
body.append(fileName+ "\"\r\n");
body.append("Content-Type: application/octet-stream");
body.append("\r\n\r\n\r\n--" + BOUNDARY + "\r\n");


HttpURLConnection conn = null;
try {
URL url = new URL("server);
conn = (HttpURLConnection) url.openConnection();

conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Accept-Charset", charset);
conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setChunkedStreamingMode(1024);
((HttpURLConnection) conn).setRequestMethod("POST");
DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
dos.write(body.toString().getBytes(charset));

int iSize, upSize = 0;
byte[] byArrTempData = new byte[1024];

InputStream inputStreamObj = null;

int notiSize = 0, notiLimit;
notiLimit = Integer.parseInt(item.getSize()) / 20;

try {
inputStreamObj = new FileInputStream(filePath);

while (true) {

if (mbStop == true)
throw new Exception("cancel....");

iSize = inputStreamObj.read(byArrTempData);
if (iSize <= 0) {
sendNotification(UPLOAD_ITEM_PROGRESS, mUploadIndex, upSize);
break;
}

upSize = upSize + iSize;
dos.write(byArrTempData, 0, iSize);

if ((upSize - notiSize) > notiLimit) {
Thread.sleep(100);
sendNotification(UPLOAD_ITEM_PROGRESS, mUploadIndex, upSize);
notiSize = upSize;
}
}
} catch (Exception e) {
if (inputStreamObj != null)
inputStreamObj.close();
return false;
}

String endBoundary = "\r\n--" + BOUNDARY + "--\r\n";
dos.write(endBoundary.getBytes(charset));

dos.flush();
dos.close();
} catch (Exception e) {
if (conn != null)
((HttpURLConnection) conn).disconnect();

return false;
} finally {
if (conn != null) {
BufferedReader reader = null;
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String is = reader.readLine();
JSONObject jobj = new JSONObject(is);

if (jobj.getBoolean(SUCCESS) != true) {
return false;
}

((HttpURLConnection) conn).disconnect();
}
}

return true;
}