Search in sources :

Example 6 with Upload

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);
}
Also used : Div(com.vaadin.flow.component.html.Div) MultiFileMemoryBuffer(com.vaadin.flow.component.upload.receivers.MultiFileMemoryBuffer) NativeButton(com.vaadin.flow.component.html.NativeButton) Upload(com.vaadin.flow.component.upload.Upload) IOException(java.io.IOException)

Example 7 with Upload

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);
}
Also used : Div(com.vaadin.flow.component.html.Div) MultiFileMemoryBuffer(com.vaadin.flow.component.upload.receivers.MultiFileMemoryBuffer) Label(com.vaadin.flow.component.html.Label) Upload(com.vaadin.flow.component.upload.Upload)

Example 8 with 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);
}
Also used : Div(com.vaadin.flow.component.html.Div) MultiFileMemoryBuffer(com.vaadin.flow.component.upload.receivers.MultiFileMemoryBuffer) Label(com.vaadin.flow.component.html.Label) Upload(com.vaadin.flow.component.upload.Upload)

Example 9 with 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);
}
Also used : MultiFileMemoryBuffer(com.vaadin.flow.component.upload.receivers.MultiFileMemoryBuffer) Upload(com.vaadin.flow.component.upload.Upload)

Example 10 with 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());
}
Also used : FileBuffer(com.vaadin.flow.component.upload.receivers.FileBuffer) MultiFileBuffer(com.vaadin.flow.component.upload.receivers.MultiFileBuffer) Upload(com.vaadin.flow.component.upload.Upload)

Aggregations

Upload (com.vaadin.flow.component.upload.Upload)11 MemoryBuffer (com.vaadin.flow.component.upload.receivers.MemoryBuffer)5 Div (com.vaadin.flow.component.html.Div)4 MultiFileMemoryBuffer (com.vaadin.flow.component.upload.receivers.MultiFileMemoryBuffer)4 H1 (com.vaadin.flow.component.html.H1)2 Hr (com.vaadin.flow.component.html.Hr)2 Label (com.vaadin.flow.component.html.Label)2 Span (com.vaadin.flow.component.html.Span)2 MultiFileBuffer (com.vaadin.flow.component.upload.receivers.MultiFileBuffer)2 IOException (java.io.IOException)2 Button (com.vaadin.flow.component.button.Button)1 Dialog (com.vaadin.flow.component.dialog.Dialog)1 NativeButton (com.vaadin.flow.component.html.NativeButton)1 TextField (com.vaadin.flow.component.textfield.TextField)1 FileBuffer (com.vaadin.flow.component.upload.receivers.FileBuffer)1 BufferedImage (java.awt.image.BufferedImage)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1