I'm trying to upload file using http post request. I figured this is doable using MultipartEntity, as such:
MultipartEntity entity = new MultipartEntity();
...
entity.addPart("caption", new StringBody("myCaption"));
entity.addPart("file", new FileBody(file));
entity.addPart("uploadername", new StringBody("myName"));
...
My problem now is the structure by which the post request needs to be made. Instead of the rather straightforward...
{
"caption":[caption],
"file":[file to upload],
"uploadername":[name]
}
..it is..
{
"newfile":
{
"caption":[caption],
"file":[file to upload]
},
"uploadername":[name]
}
If I don't need to post files, I can use JSONObject and put one JSONObject inside the other, but I can't figure out a way to do so for MultipartEntity. Any clues? Thanks in advance.
..Okay, guess I found a way to do it.