1 回答
TA贡献1906条经验 获得超10个赞
原来问题是我试图处理/取消错误的对象。我将代码调整为以下内容:
private Disposable disposable;
private void myMethod(){
Flowable<Progress<FileLink>> upload = new Client(myConfigOptionsHere)
.uploadAsync(filePath, false, storageOptions);
this.disposable = upload.doOnNext(progress -> {
double progressPercent = progress.getPercent();
if(progressPercent > 0){
//Updating progress here
}
if (progress.getData() != null) {
//Sending successful upload callback here
}
})
.doOnComplete(new Action() {
@Override
public void run() throws Exception {
//Logging he complete action here
}
})
.doOnCancel(new Action() {
@Override
public void run() throws Exception {
//Logging the cancel here
}
})
.doOnError(new Consumer<Throwable>() {
@Override
public void accept(Throwable t) throws Exception {
//Logging the error here
}
})
.subscribe();
}
public void cancelUpload(){
if(this.disposable != null){
this.disposable.dispose();
this.disposable = null;
}
}
并且能够让它正常工作。本质上,您需要dispose()针对对象调用方法dispose,而不是Flowable.
添加回答
举报