http-request
http-request copied to clipboard
UploadProgress Problem
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!
same here
Call chunk(0) on the request object before adding the part.