大家好我正在将多页文件上传到服务器并且文件上传成功。我想在上传时获取进度百分比是我的代码
ArrayList<SelectedFiles> selectedfiles = new ArrayList<>();
private void UploadFilestoServer() {
CustomUtils.ShowProgress(this);
MultipartBody.Builder builder = new MultipartBody.Builder();
builder.setType(MultipartBody.FORM);
Call<ResponseBody> call = null;
builder.addFormDataPart("email", user_mail);
for (int i = 0; i < selectedfiles.size(); i++) {
File file = new File(selectedfiles.get(i).getFilepath());
builder.addFormDataPart("file[]", file.getName(), RequestBody.create(MediaType.parse("multipart/form-data"), file));
MultipartBody requestBody = builder.build();
call = service.uploadFile(requestBody);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
CustomUtils.HideProgressDialog();
finish();
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
CustomUtils.HideProgressDialog();
}
});
}
}