正在发送Api的Hashmap中的字符串参数集合。现在需要添加一个必须为Image的参数File。
POST接口的正文如下:
Key1, Value1, Text
Key2, Value2, Text
Key3, Value3, File
我见过许多多部分请求的例子,但都没有解决这个问题。寻找一种方法/例子。
发布于 2016-04-03 04:19:31
备注:这是以文件形式发送图像的另一种方式。
您可以尝试将图像转换为BASE64字符串,并将其作为字符串发送。
首先,将您的位图转换为字节数组:
//can use lower value than 100 for more compression or change compression format as JPEG
ByteArrayOutputStream bAOS = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, bAOS);
byte[] byteArray = bAOS.toByteArray();
然后,将其编码为BASE64字符串:
String encodedString = Base64.encodeToString(byteArray, Base64.DEFAULT);
最后,将其作为字符串放到您的hashmap中。
https://stackoverflow.com/questions/36378106
复制相似问题