我有下面的代码,我想知道如何能够获得除设置的Boolean
值之外的其他响应:
public Single<Boolean> uploadFile(String entityType, String entityId, String blobName){
return Single.create(e -> {
uploadElement = DOM.createElement("input");
uploadElement.setAttribute("type", "file");
uploadElement.setAttribute("accept", "*/*");;
Event.sinkEvents(uploadElement, Event.ONCHANGE);
Event.setEventListener(uploadElement, event -> {
final FileObject fileObject = (FileObject) getFile(event);
log("Name=" + fileObject.getName());
log("Type=" + fileObject.getType());
log("Size=" + fileObject.getSize() + "");
readAsDataURL((FileObject) fileObject, new FileReaderCallback() {
@Override
public void onLoad(String data) {
Entity entity = new Entity(entityType);
entity.setEntityId(entityId);
entity.setBlobProperty(blobName, data).subscribe(isSuccess -> {
e.onSuccess(isSuccess);
}, error -> {
e.onError(error);
});
}
});
});
click();
});
}
我需要能够在这个过程中获得FileObject
,我如何在RxJava中做到这一点?
发布于 2018-09-21 13:10:45
看一下zip操作符。这是您的结果加上您放入zip运算符的内容的元组。你可能需要稍微调整一下你的程序结构。
发布于 2018-09-21 04:43:19
您可以返回一个Single<MyCustomResult>
,而不是Single<Boolean>
,其中MyCustomResult
有一个boolean
字段和一个FileObject
字段。
而不是e.onSuccess(isSuccess)
,你可以写:
e.onSuccess(new MyCustomResult(isSuccess, fileObject));
https://stackoverflow.com/questions/52432499
复制相似问题