http-request icon indicating copy to clipboard operation
http-request copied to clipboard

UploadProgress Problem

Open xmavara opened this issue 10 years ago • 2 comments
trafficstars

hi, i wrote a bit code for upload file. everything is okay other than UploadProgress. the problem is after execute task, uploaded value immediately and lower than 1 second growing and will be equal total value. but upload takes many seconds. below is my code:

   protected File doInBackground(String... urls) {
        try {
            File file = new File(Environment.getExternalStorageDirectory().getPath() + "/Download/a.jpg");
            HttpRequest req = HttpRequest.post(urls[0]);

            req.progress(new UploadProgress() {
                @Override
                public void onUpload(long uploaded, long total) {
                    publishProgress(uploaded, total);
                }
            });

            req.part("profile_picture", "a.jpg", "multipart/form-data", file);

            if (req.ok()) {
                System.out.println("Response was: " + req.body());
                publishProgress(file.length(), file.length());
                progressBar.dismiss();
            } else {
                System.out.println("Response was: Failed");
            }

            return file;
        } catch (HttpRequestException exception) {
            exception.printStackTrace();
            return null;
        }
    }

    protected void onProgressUpdate(Long... progress) {
        long progressPercentage = (int) 100 * progress[0] / progress[1];
        System.out.println(progressPercentage);
        progressBar.setProgress((int) progressPercentage);
    }

please help me!

xmavara avatar May 03 '15 23:05 xmavara

same here

bakua avatar May 19 '15 14:05 bakua

Call chunk(0) on the request object before adding the part.

andrewtoth avatar Jul 28 '15 16:07 andrewtoth