Recent Posts
Recent Comments
반응형
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Archives
Today
Total
관리 메뉴

오늘도 공부

Using MultipartEntity in Android applications 본문

Android/Tip&Tech

Using MultipartEntity in Android applications

행복한 수지아빠 2011. 7. 11. 10:24
반응형
출처 : http://blog.tacticalnuclearstrike.com/2010/01/using-multipartentity-in-android-applications/

Using MultipartEntity in Android applications

To be able to upload files from an Android application and use the Multipart content type you need to add some additional jar files to your application.

The files needed are apache-mime4j, httpclient, httpcore and httpmime. All are opensource projects built by the Apache foundation.

Download the 4 files and add them to your project then you should be able to use the following code to post strings and files to pages.

01
02
03
04
05
06
07
08
09
10
11
12
13
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.tumblr.com/api/write");
  
try {
  MultipartEntity entity = new MultipartEntity();
  
  entity.addPart("type", new StringBody("photo"));
  entity.addPart("data", new FileBody(image));
  httppost.setEntity(entity);
  HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
} catch (IOException e) {
}

The image variable in this case is a File that contains an image captured by the camera on the phone.

반응형