Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Die Upload-Komponente ermöglicht den Zugriff auf das lokale Dateisystem des Client, um beliebige Dateien auszuwählen und anschließend auf den Server hochzuladen. Die Komponente besteht aus einem Button, der den lokalen Dateimanger aufruft und die Auswahl einer Datei ermöglicht sowie aus einem zweiten Button, der den Upload-Vorgang startet. Zwischen den Buttons wird der Name der ausgewählten Datei angezeigt.

Image Removed

Die Upload-Komponente benötigt einen "Receiver", der auf Serverseite die Datei empfängt und weiterverarbeitet. 

Wichtige Properties:

...

With the upload component, you can access the local file system of the client to select any files and upload them on the server. The component consists of two buttons: the first opens the local file manager and enables the selection of a file, whereas the second starts the upload activity. The name of the selected file will be displayed between the two buttons.

Image Added

The upload component requires a "receiver" which receives the file on the server side and processes it.

Important properties:
  • ButtonCaption - Label of the upload button.
  • Include Page
    Property Caption
    Property Caption
  • Receiver - Der Receiver ist ein Objekt, das die Verarbeitung der Datei auf Serverseite übernimmt - The receiver is an object that processes the file on the server side.
  • Include Page
    Property TabIndex
    Property TabIndex

...

Important events
  • uploadFailed - Wird ausgelöst, wenn der Upload fehlschlägt - Is triggered when the upload fails.
  • uploadFinished - Wird ausgelöst, sobald der Upload beendet ist. Zu diesem Zeitpunkt steht noch nicht fest, ob der Upload erfolgreich war oder nicht.
  • updateProgress - Wird regelmäßig während des Uploads ausgelöst. Damit ist es möglich, den Fortschritt des Uploads zu verfolgen.
  • uploadStarted - Wird ausgelöst, sobald der Upload begonnen hat.
  • uploadSucceeded - Wird ausgelöst, sobald der Upload beendet ist und erfolgreich war.
Databinding:
  • Kein Databinding vorhanden. 
Examples:
  • Upload einer Datei - Is triggered as soon as the upload has ended. At this point, it is still not clear if the upload was successful.
  • updateProgress - Is triggered regularly during the upload. Thus it is possible to track the progress of the upload.
  • uploadStarted - Is triggered as soon as the upload has started.
  • uploadSucceeded - Is triggered as soon as the upload has ended and was successful.
Data binding:
  • No data binding available.
Examples:
  • File upload


Code Block
languagejava
themeConfluence
// For later usage, e.g. in a message displayed by uploadSucceeded-Event
File file;


// Build receiver
Receiver receiver = new Receiver() {

	@Override
	public OutputStream receiveUpload(final String filename, final String mimeType) {
        // Create upload stream to write to

        FileOutputStream fos = null;
        try {

        	// Get path to servlet's temp directory
        	final File temporaryDirectory = (File) VaadinServlet.getCurrent().getServletContext().getAttribute(ServletContext.TEMPDIR);

            // Concatenate temporaryDirectory with filename and open the file for writing.
            file = new File(temporaryDirectory, filename);

        	// Create the output stream
            fos = new FileOutputStream(file);

        } catch (final java.io.FileNotFoundException e) {
            Notification.show("Could not open file", Type.ERROR_MESSAGE);
            return null;
        }
        return fos;
	}
};

// Set Receiver for upload component
upload.setReceiver(receiver);