Reputation: 35276
I have this code below and I want to know how to be able to get additional response other than the set Boolean
value:
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();
});
}
I need to be able to get the FileObject
also in the process, how can I do that in RxJava?
Upvotes: 1
Views: 55
Reputation: 2268
Look at the zip operator. That makes a tuple of you result plus what you put in the zip operator. You might have to restructure your program a bit.
Upvotes: 1
Reputation: 8889
Instead of a Single<Boolean>
, you could return a Single<MyCustomResult>
, where MyCustomResult
has a boolean
field and a FileObject
field.
Instead of e.onSuccess(isSuccess)
you'd write:
e.onSuccess(new MyCustomResult(isSuccess, fileObject));
Upvotes: 0