I am trying to send MultiPartEntity
to the server to upload an image.
I have to send data to the server with a MultiPartEntity
, The following is a sample request.
{
"user": {
"id": "12345",
"primary_account_id": "43566"
},
"poster_photo": {
"title": "photo test",
"image": *uploaded image
}
}
Does anyone have an idea on how to do this?
Please help me solve this.
Just try out this link. It has sample code on what you are trying to acheive.
http://www.coderzheaven.com/?p=2770
There are two way to achieve your goal.
1)Using JSON
Android Side:- First thing is JSON format can support only string data, so you can add only string data. If you want to add image in JSON format so you have to convert
Image to String
. Image into bytearrayServer Side:- Decode byte string and convert in Image.
2)Using NameValuePair
Android Side:- Used NameValuePair instead of JSON, for this way follow link which HardikJoshi given in comment (Link)
Server Side:- Change server code JSON to NameValuePair.
I suggest Second Way is easy to implement & understand..