如何上传JSON请求Android的多部分图像数据吗? [英] How to upload multipart Image data in json request Android?

查看:125
本文介绍了如何上传JSON请求Android的多部分图像数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JSON请求,以便任何人都可以帮助我在这里多部分后上传图像数据。

I have to upload image data in multipart post using json request so can anyone help me out here.

下面是我的JSON字符串请求发送服务器(我能够在字符串创建JSON请求,但如何发送code要求

Here is my json string request to send server (I am able to create JSON request in string but how to send that code is required)

{
"Request": {
    "data": {
        "Key": "keydata",
        "info": {},
        "param": {
            "title": "Testingpostmultipartimageupload",
            "photo": **"IMAGE BYTE DATA"**,
            "photoFilename": "Test.png"
        }
    },
    "info": {}
}

}

所以,我怎么可以在JSON图像字节数据web服务一起发布此数据...

So how can I post this data along with image byte data in JSON to webservice...

先谢谢了。

推荐答案

我发现我的解决方案,在此基础上一篇:<一href=\"http://prativas.word$p$pss.com/2014/03/03/uploading-image-from-android-app-to-server-programmatically/\" rel=\"nofollow\">http://prativas.word$p$pss.com/2014/03/03/uploading-image-from-android-app-to-server-programmatically/:

I found my solution based on this post: http://prativas.wordpress.com/2014/03/03/uploading-image-from-android-app-to-server-programmatically/:

和与JSON数据一个多合这样的:

And combined this with a multipart for the json data:

// the json values:
multiPartEntityBuilder.addPart("fieldname", new StringBody("value",ContentType.APPLICATION_JSON));

//the file:
File file = new File(filename);
FileBody fileBody = new FileBody(file);
multiPartEntityBuilder.addPart("FIle_Fieldname_depending_on_the_api", fileBody);

这文件上载到一个REST API(Django的restframework)

This uploads the file to a rest api (django restframework)

这篇关于如何上传JSON请求Android的多部分图像数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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