use of com.vaadin.flow.component.upload.receivers.MultiFileMemoryBuffer in project flow-components by vaadin.
the class UploadView method createSimpleUpload.
private void createSimpleUpload() {
Div output = new Div();
Div eventsOutput = new Div();
Div fileList = new Div();
MultiFileMemoryBuffer buffer = new MultiFileMemoryBuffer();
Upload upload = new Upload(buffer);
upload.addSucceededListener(event -> {
try {
output.add(event.getFileName());
output.add(IOUtils.toString(buffer.getInputStream(event.getFileName()), "UTF-8"));
} catch (IOException e) {
e.printStackTrace();
}
eventsOutput.add("-succeeded");
});
upload.addAllFinishedListener(event -> eventsOutput.add("-finished"));
NativeButton clearFileListBtn = new NativeButton("Clear file list", e -> upload.clearFileList());
NativeButton printFileListBtn = new NativeButton("Print file list", e -> fileList.setText(upload.getElement().getProperty("files")));
upload.setMaxFileSize(500 * 1024);
upload.setId("test-upload");
clearFileListBtn.setId("clear-file-list");
printFileListBtn.setId("print-file-list");
fileList.setId("file-list");
output.setId("test-output");
eventsOutput.setId("test-events-output");
addCard("Simple in memory receiver", upload, output, eventsOutput, fileList, clearFileListBtn, printFileListBtn);
}
use of com.vaadin.flow.component.upload.receivers.MultiFileMemoryBuffer in project docs by vaadin.
the class UploadErrorMessages method setupRecommendedExample.
private Div setupRecommendedExample() {
MultiFileMemoryBuffer buffer = new MultiFileMemoryBuffer();
// tag::snippet[]
Upload upload = new Upload(buffer);
upload.setDropAllowed(false);
UploadExamplesI18N i18N = new UploadExamplesI18N();
i18N.getUploading().getError().setUnexpectedServerError("File couldn't be uploaded, please try again later");
upload.setI18n(i18N);
// end::snippet[]
Label label = new Label("Recommended");
label.getStyle().set("font-weight", "600");
upload.setId("upload-recommended");
label.setFor(upload.getId().get());
// hidden-source-line
upload.getElement().callJsFunction("setupMockErrorResponse");
// hidden-source-line
upload.getElement().executeJs("this.files = this.createFakeFilesUploadErrorMessagesB()");
return new Div(label, upload);
}
use of com.vaadin.flow.component.upload.receivers.MultiFileMemoryBuffer in project docs by vaadin.
the class UploadErrorMessages method setupCautionExample.
private Div setupCautionExample() {
MultiFileMemoryBuffer buffer = new MultiFileMemoryBuffer();
Upload upload = new Upload(buffer);
upload.setDropAllowed(false);
UploadExamplesI18N i18N = new UploadExamplesI18N();
i18N.getUploading().getError().setUnexpectedServerError("Unexpected Server Error");
upload.setI18n(i18N);
Label label = new Label("Caution");
label.getStyle().set("font-weight", "600");
upload.setId("upload-caution");
label.setFor(upload.getId().get());
// hidden-source-line
upload.getElement().callJsFunction("setupMockErrorResponse");
// hidden-source-line
upload.getElement().executeJs("this.files = this.createFakeFilesUploadErrorMessagesA()");
return new Div(label, upload);
}
use of com.vaadin.flow.component.upload.receivers.MultiFileMemoryBuffer in project aire-components by aire-ux.
the class UploadPluginOverlay method addContent.
private void addContent() {
buffer = new MultiFileMemoryBuffer();
upload = new Upload(buffer);
upload.getStyle().set("height", "100%");
upload.setAutoUpload(true);
upload.addSucceededListener(this);
addContent(upload);
}
Aggregations