use of elemental2.dom.FileReader in project kie-wb-common by kiegroup.
the class DocumentUploadManager method initFileReader.
public void initFileReader() {
fileReader = new FileReader();
fileReader.onload = event -> {
if (fileReader.readyState == FileReader.DONE) {
String[] split = fileReader.result.asString().split(",");
String content = "";
if (split.length == 2) {
content = split[1];
}
if (activeSession == null) {
return null;
}
DocumentUploadChunk newChunk = new DocumentUploadChunk(activeSession.documentId, activeSession.file.name, activeSession.chunk, activeSession.maxChunks, content);
uploadService.call((RemoteCallback<DocumentUploadResponse>) response -> {
if (response.getState().equals(DocumentUploadResponse.DocumentUploadState.FINISH)) {
activeSession.onUploadEnd.execute(response.isSuccess());
activeSession = null;
startUpload();
} else if (!response.isSuccess()) {
activeSession.onUploadEnd.execute(response.isSuccess());
activeSession = null;
startUpload();
}
}, (ErrorCallback<Message>) (message, throwable) -> {
activeSession.onUploadEnd.execute(false);
activeSession = null;
startUpload();
return false;
}).uploadContent(newChunk);
if (activeSession.nextChunk <= activeSession.file.size) {
upload(activeSession.nextChunk);
}
}
return null;
};
}
Aggregations