HttpClient Post with progress and MultipartEntityBuilder

后端 未结 1 797
夕颜
夕颜 2020-12-03 09:12

I try to implement an progress while uploading an file with HttpClient 4.3.3 and MultipartEntityBuilder

So actually i execute a post reques

相关标签:
1条回答
  • 2020-12-03 09:35

    I just found a solution for that:

    You need an HttpEntityWrapper which counts the processed bytes and has a callback.

    ProgressHttpEntityWrapper.ProgressCallback progressCallback = new ProgressHttpEntityWrapper.ProgressCallback() {
    
            @Override
            public void progress(float progress) {
                //Use the progress
            }
    
        }
    
    httpPost.setEntity(new ProgressHttpEntityWrapper(entityBuilder.build(), progressCallback));
    

    And here is the complete code from the ProgressHttpEntityWrapper: https://github.com/x2on/gradle-hockeyapp-plugin/blob/master/src/main/groovy/de/felixschulze/gradle/util/ProgressHttpEntityWrapper.groovy

    Main source for this solution: https://stackoverflow.com/a/7319110/268795

    0 讨论(0)
提交回复
热议问题