Sending images using Http Post

前端 未结 5 1249
轮回少年
轮回少年 2020-11-22 05:52

I want to send an image from the android client to the Django server using Http Post. The image is chosen from the gallery. At present, I am using list value name Pairs to s

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 06:06

    The loopj library can be used straight-forward for this purpose:

    SyncHttpClient client = new SyncHttpClient();
    RequestParams params = new RequestParams();
    params.put("text", "some string");
    params.put("image", new File(imagePath));
    
    client.post("http://example.com", params, new TextHttpResponseHandler() {
      @Override
      public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
        // error handling
      }
    
      @Override
      public void onSuccess(int statusCode, Header[] headers, String responseString) {
        // success
      }
    });
    

    http://loopj.com/

提交回复
热议问题