How to send a “multipart/form-data” POST in Android with Volley

后端 未结 9 2286
不思量自难忘°
不思量自难忘° 2020-11-22 03:50

Has anyone been able to accomplish sending a multipart/form-data POST in Android with Volley yet? I have had no success trying to upload an image/png

9条回答
  •  不知归路
    2020-11-22 04:29

    Another solution, very light with high performance with payload large:

    Android Asynchronous Http Client library: http://loopj.com/android-async-http/

    private static AsyncHttpClient client = new AsyncHttpClient();
    
    private void uploadFileExecute(File file) {
    
        RequestParams params = new RequestParams();
    
        try { params.put("photo", file); } catch (FileNotFoundException e) {}
    
        client.post(getUrl(), params,
    
            new AsyncHttpResponseHandler() {
    
                public void onSuccess(String result) {
    
                    Log.d(TAG,"uploadFile response: "+result);
    
                };
    
                public void onFailure(Throwable arg0, String errorMsg) {
    
                    Log.d(TAG,"uploadFile ERROR!");
    
                };
    
            }
    
        );
    
    }
    

提交回复
热议问题