I am trying to upload image fromandroid to asp.net server. I am following following procedure. convert image from bitmap to byte[] yhen byte[] to string and pass this string to the asp.net web service is this correct way to save image on to the .net server Please Give the solution to upload image from android to asp.net server both client and server side code .
Asked
Active
Viewed 6,371 times
0
-
Yes, it's the correct way to save image on the server. – Axarydax Mar 13 '14 at 07:03
-
but i am not able to save image on to the server – user2346928 Mar 13 '14 at 07:04
-
Are you experiencing problems with any step of your solution? If so, please ask specifically about them. – Axarydax Mar 13 '14 at 07:04
-
is the web service being called? Do the correct bytes arrive? do you receive an exception in your Android app? – Axarydax Mar 13 '14 at 07:05
-
problem is that i am passing parameter string to the .net web service it says that to much length. – user2346928 Mar 13 '14 at 07:07
-
How are you calling the web service? Do you encode the whole file into a string and pass it as a HTTP GET parameter? – Axarydax Mar 13 '14 at 07:09
-
yes encoded string pass to the web service .. – user2346928 Mar 13 '14 at 07:14
-
call web service using json parser – user2346928 Mar 13 '14 at 07:14
3 Answers
1
The simplest way is convert your bitmap to base64
string :
public String encodeTobase64(Bitmap image)
{
Bitmap immagex=image;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
immagex.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
String imageEncoded = Base64.encodeToString(b, Base64.DEFAULT);
return imageEncoded;
}
after converting ,you can send the string to webservice, on the server side, you must decode this string to an image !
To convert base64 to image on server side,duckduckgo
or google will help you :

S.M_Emamian
- 17,005
- 37
- 135
- 254
0
If not too late, here is my suggested solution:
- Server side: you can create a web service or RESTful application on the .NET Framework. Microsoft provides ASP.NET Web API. You can start from their website here
- Client side: your Android here. You can refer to some of the following: Volley, Retrofit...
If you want to use Volley, you can refer to some following links:
- Working POST Multipart Request with Volley and without HttpEntity
- How to send a “multipart/form-data” POST in Android with Volley
- Trouble Sending Multipart File with Boundary via Volley
Of course, you can find more available in SO.
Hope this helps!