• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

how to upload image from android to restful webservice using jersey

Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to upload image to rest webservice(JAXRS) using jersey which will insert the image into my sql...
i hav successfully inserted image from rest webservice....but hav no idea of how to accept from android client...
my android code is
view plaincopy to clipboardprint?
public class AndroidPostImageActivity extends Activity {
Bitmap bm;

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
try {
// bm = BitmapFactory.decodeResource(getResources(),
// R.drawable.forest);
bm = BitmapFactory.decodeFile("/sdcard/Blue hills.jpg");
} catch (Exception e) {
Log.e(e.getClass().getName(), e.getMessage());

public void executeMultipartPost() throws Exception {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bm.compress(CompressFormat.JPEG, 75, bos);
byte[] data = bos.toByteArray();
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(
ByteArrayBody bab = new ByteArrayBody(data, "forest.jpg");
// File file= new File("/mnt/sdcard/forest.png");
// FileBody bin = new FileBody(file);
MultipartEntity reqEntity = new MultipartEntity(
reqEntity.addPart("uploaded", bab);
//reqEntity.addPart("photoCaption", new StringBody("sfsdfsdf"));
HttpResponse response = httpClient.execute(postRequest);
BufferedReader reader = new BufferedReader(new InputStreamReader(
response.getEntity().getContent(), "UTF-8"));
String sResponse;
StringBuilder s = new StringBuilder();

while ((sResponse = reader.readLine()) != null) {
s = s.append(sResponse);
System.out.println("Response: " + s);
} catch (Exception e) {
// handle exception here
Log.e(e.getClass().getName(), e.getMessage());

need to take image as multipart data and insert in to database.
looking for suggestions
    Bookmark Topic Watch Topic
  • New Topic