How to send files with JSON on Android?

I want to send JSON files with HTTP client. I don't know how to start. Anyone can suggest what I should do? I will send data about this JSON format:

 {
    "Filename": "282850ad-de5c-498f-8280-2d4b6d77b774.jpg",
    "ChunkId":1,
    "ChunkLength":11397,
    "FileLength":11397
 }

As you can see, I will send the file in blocks. I don't know if I want to convert the file into a byte array. If I need, anyone can give me some sample code. Thank you

resolvent:

To send a text file or an image file on the server, you can use multiparty

DefaultHttpClient localDefaultHttpClient = new DefaultHttpClient();

      FileBody localFileBody = new FileBody(new File(this.picturePath), "image/jpg");
      HttpPost localHttpPost = new HttpPost("http://website.com/path/....");
      multipartentity localmultipartentity = new multipartentity(HttpMultipartMode.BROWSER_COMPATIBLE);
      try
      {
        Log.d("picturepath", this.picturePath);
        localmultipartentity.addPart("Email", new StringBody("emailid@gmail.com"));
        localmultipartentity.addPart("password", new StringBody("password"));
        localmultipartentity.addPart("phone", new StringBody("9875......."));
        localmultipartentity.addPart("profilepicture", localFileBody);
        localHttpPost.setEntity(localmultipartentity);
        HttpResponse localHttpResponse = localDefaultHttpClient.execute(localHttpPost);
        System.out.println("responsecode" + localHttpResponse.getStatusLine().getStatusCode());
}
catch (Exception e)
      {
        Log.d("exception", e.toString());
      }

This is valid because this code is part of my running project

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>