use of com.vaadin.flow.component.upload.Upload 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.Upload 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.Upload 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.Upload 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);
}
use of com.vaadin.flow.component.upload.Upload in project flow-components by vaadin.
the class FileBufferView method createSingleFileUpload.
private static Div createSingleFileUpload() {
final FileBuffer buffer = new FileBuffer();
final Upload singleFileUpload = new Upload(buffer);
singleFileUpload.setId("single-upload");
singleFileUpload.setMaxFiles(1);
return setupUploadSection(singleFileUpload, e -> buffer.getInputStream());
}
Aggregations