开发者

How to upload multipart Image data in json request Android?

开发者 https://www.devze.com 2023-04-09 12:10 出处:网络
I have to upload image data in multipart post using json request so can anyone help me out here. Here is my json string request to send server (I am able to create JSON request in string but how to s

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

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"开发者_C百科
        }
    },
    "info": {}
}

}

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

Thanks in advance.


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

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);

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

0

精彩评论

暂无评论...
验证码 换一张
取 消