在Android的纯文本一起MultiPartEntity [英] MultiPartEntity along with plain text in android

查看:110
本文介绍了在Android的纯文本一起MultiPartEntity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图发送 MultiPartEntity 到服务器上上传图片。

我必须将数据发送到服务器以 MultiPartEntity ,下面是一个简单的请求。

  {
  用户:{
    ID:12345,
    primary_account_id:43566
  },
  poster_photo:{
    头衔:照片测验,
    形象:*上传的图片
  }
}

有没有人对如何做到这一点的想法?

请帮我解决这个问题。


解决方案

有实现自己的目标双向。

1)使用JSON

Android的阵营: - 的第一件事是JSON格式只能支持字符串数据,所以你可以只添加字符串数据。如果你想要让你不得不图像转换为字符串添加JSON格式的图像。 <一href=\"http://stackoverflow.com/questions/10513976/how-to-convert-image-into-byte-array-and-byte-array-to-base64-string-in-android\">Image成的bytearray

服务器端: - 德code字节串并转换图像

2)使用的NameValuePair <​​/ STRONG>

Android的阵营: - 使用的NameValuePair而不是JSON,对于这种方式遵循的HardikJoshi评论中给出的链接(<一个href=\"http://stackoverflow.com/questions/12422541/how-to-send-multiple-images-to-server-using-multipartentity-from-android\">Link)

服务器端: - 更改服务器code JSON来的NameValuePair <​​/ P>

我建议第二种方法是很容易实现&安培;明白..

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.

解决方案

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

这篇关于在Android的纯文本一起MultiPartEntity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆