MultiPartEntity along with plain text in android

2019-07-29 07:25发布

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.

2条回答
2楼-- · 2019-07-29 08:02

Just try out this link. It has sample code on what you are trying to acheive.

http://www.coderzheaven.com/?p=2770

查看更多
冷血范
3楼-- · 2019-07-29 08:13

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 bytearray

Server 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..

查看更多
登录 后发表回答