서버에 이미지를 업로드하고 싶습니다. 여기 json 객체로 안드로이드 다중 이미지 업로드
는 코드try {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(Constants.yigit);
Charset chars = Charset.forName("UTF-8"); // Setting up the encoding
MultipartEntity reqEntity = new MultipartEntity();
StringBody jsonBody = new StringBody(getNewDemandRequestParams(), "application/json",null);
FormBodyPart jsonBodyPart = new FormBodyPart("data", jsonBody);
reqEntity.addPart(jsonBodyPart);
if (getMainActivity().getImagesSavedData(0).size() > 0) {
for (int i = 0; i < getMainActivity().getImagesSavedData(0).size(); i++) {
File _file = new File(getMainActivity().getImagesSavedData(0).get(i).getFilePath());
FileBody _fileBody = new FileBody(_file, "image/jpg", "UTF-8");
FormBodyPart fileBodyPart = new FormBodyPart(getMainActivity().getImagesSavedData(0).get(i).getImageName().replace(".jpg", ""), _fileBody);
reqEntity.addPart(fileBodyPart);
reqEntity.addPart(getMainActivity().getImagesSavedData(0).get(i).getImageName().replace(".jpg",""), _fileBody);
}
}
post.setEntity(reqEntity);
String result = EntityUtils.toString(reqEntity);
Log.e("rsul", result);
HttpResponse response = client.execute(post);
resEntity = response.getEntity();
final String response_str = EntityUtils.toString(resEntity);
}
그러나 문제는 jsonBodyPart 슬래시 포함된다. 이 같은
요청 본문 :
{ "데이터"=> "{\"조치 \ "\"YENITALEP \ ", \"응용 프로그램 \ ": {\"버전 \ "\" \ "데이터 \": \ "청구서 \": \ "이미지 이름 \": \ "1395914025134 \", \ "참고 \": \ "\", \ "유형 \": \ " \ "노트 \": \ "알림 \": \ "타이핑 \": \ "BeniAray? n \", \ " HTC 하나 ", \"하드웨어 모델 \ \ "timestamp \": \ "Date (1391073711000 + 0200) \"systemVersion \ ": \"4.4.2 \ ", \"uid \ ": \"00000000-7f39-faab-b500-7f280e9b4fed \ "}", "1395914025134"=, # @ original_filename = "1395914025134.jpg", @ content_type = "image/jpg; charset = UTF-8", @hea ders = "내용 - 처리 : 양식 데이터; name = \ "1395914025134 \"; 파일 이름 = \ "1395914025134.jpg \"\ r \ n 내용 유형 : image/jpg; 문자셋 = UTF-8 \ 연구 \ nContent 전송 인코딩 : 나는 여러 부분을 사용하여 감사합니다 도움 복잡한 JSON 객체와 이미지를 게시 할 수있는 방법 진 \ 연구 \ n을 ">}