Search in sources :

Example 1 with FileReader

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;
    };
}
Also used : ErrorCallback(org.jboss.errai.common.client.api.ErrorCallback) FileReader(elemental2.dom.FileReader) DocumentUploadChunk(org.kie.workbench.common.forms.jbpm.service.shared.documents.DocumentUploadChunk) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback)

Aggregations

FileReader (elemental2.dom.FileReader)1 ErrorCallback (org.jboss.errai.common.client.api.ErrorCallback)1 RemoteCallback (org.jboss.errai.common.client.api.RemoteCallback)1 DocumentUploadChunk (org.kie.workbench.common.forms.jbpm.service.shared.documents.DocumentUploadChunk)1