MultiPartEntity along with plain text in android

两盒软妹~` 提交于 2019-12-24 16:37:33

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/13081831/multipartentity-along-with-plain-text-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!