게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
안드로이드 파일업로드 관련해서 조언부탁드립니다 ㅠㅠ
게시물ID : programmer_9581짧은주소 복사하기
작성자 : LemoLemo
추천 : 0
조회수 : 1870회
댓글수 : 1개
등록시간 : 2015/04/27 20:37:07
옵션
  • 본인삭제금지
안녕하세요

프로잭트중에 너무 막막한부분이있어서 질문드려요 ㅠㅠ

안드로이드 웹뷰로 작업중인데요

4.4버전에서 파일업로드가 안되는관계로

네이티브 단에서 파일업로드를 구현중인데요

multipart라이브러리를 이용해서 파일업로드는하는데

파일과 json형식의 데이터를 같이보내줘야하는데

아무리 구글링해도 답이 나오지않네요 ㅠㅠ

Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData();
intent.getData();
String imageFilePath = getImagePathToUri(intent.getData()); 
File selectImageFile = new File(imageFilePath);
JSONObject json= new JSONObject();
json.put("data", "sample");

MultipartEntityBuilder builder = MultipartEntityBuilder.create() 
.setCharset(Charset.forName("UTF-8"))
.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
if(selectImageFile != null){
builder.addPart("content", new FileBody(selectImageFile));
}
// HttpClient client = AndroidHttpClient.newInstance("Android");
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("server_url");
try {
   post.setEntity(builder.build()); 
   HttpResponse httpRes;
   httpRes = client.execute(post);
   HttpEntity httpEntity = httpRes.getEntity();
   if (httpEntity != null) {
       String response = EntityUtils.toString(httpEntity);
       Log.e("res",response);
   }
} catch (UnsupportedEncodingException e) {
} catch (ClientProtocolException e1) {
} catch (IOException e1) {
} catch (ParseException e) {
}


조언부탁드립니다 ㅠㅠ
꼬릿말 보기
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호