• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to upload image from android to restful webservice using jersey  RSS feed

Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • 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
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!