---
title: "How to upload image to server with Android?"  
description: "How to upload image to server with Android?"  
author: "marcel ethan"  
published: 2014-10-14  
updated: 2014-10-14  
canonical: https://www.mindstick.com/forum/2375/how-to-upload-image-to-server-with-android  
category: "android"  
tags: ["android", "mobile development"]  
reading_time: 1 minute  

---

# How to upload image to server with Android?

Here is the [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii).

```
Bitmap bm = myImageToUpload;ByteArrayOutputStream bos = new ByteArrayOutputStream();bm.compress(CompressFormat.JPEG, 100, bos);byte[] data = bos.toByteArray();HttpClient httpClient = new DefaultHttpClient();HttpPost postRequest = new HttpPost(myServerURL);ByteArrayBody bab = new ByteArrayBody(data, imageName);MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);reqEntity.addPart("uploadedfile", bab);reqEntity.addPart("fileName", new StringBody("image"));reqEntity.addPart("mimeType", new StringBody("images/jpeg"));reqEntity.addPart("extraInfo", new StringBody(extraInfo));postRequest.setEntity(reqEntity);HttpResponse response = httpClient.execute(postRequest);
```

\
his code uploads my [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) along with some other information to the [server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over). Is there a better way to do this?My concerns - It is slow, Sometimes takes 20 minuets to [upload](https://www.mindstick.com/forum/12860/how-to-upload-file-asynchronously-using-generic-handler) a [large](https://www.mindstick.com/interview/34471/what-is-a-large-language-model-llm) image to the server. The [size](https://www.mindstick.com/forum/159799/how-can-you-manage-the-size-of-mdf-and-ldf-files) of the image on the server is larger than the original.at the very [least](https://yourviews.mindstick.com/story/1471/5-autobiographies-you-should-read-at-least-once), how can I upload the image so that the image on the server is the exact same size as the image on my [android device](https://www.mindstick.com/articles/342298/best-ways-to-customize-your-android-device-for-better-productivity)?

## Replies

### Reply by Anonymous User

reqEntity.addPart("uploadedfile", new FileBody(new File(myImageToUpload)));\
This might be faster, and reads more easily, unless you really need the byte array.\


---

Original Source: https://www.mindstick.com/forum/2375/how-to-upload-image-to-server-with-android

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
