Class Upload

  • All Implemented Interfaces:
    ConnectorEventListener, ContextClickEvent.ContextClickNotifier, MethodEventSource, SerializableEventListener, ClientConnector, Sizeable, VariableOwner, com.vaadin.shared.Connector, Component, Component.Focusable, LegacyComponent, Serializable, EventListener

    @Deprecated
    public class Upload
    extends AbstractLegacyComponent
    implements Component.Focusable, LegacyComponent
    Deprecated.
    As of 8.0 replaced by Upload that is by default in immediate mode.
    Component for uploading files from client to server.

    The visible component consists of a file name input box and a browse button and an upload submit button to start uploading.

    The Upload component needs a java.io.OutputStream to write the uploaded data. You need to implement the Upload.Receiver interface and return the output stream in the receiveUpload() method.

    You can get an event regarding starting (StartedEvent), progress (ProgressEvent), and finishing (FinishedEvent) of upload by implementing StartedListener, ProgressListener, and FinishedListener, respectively. The FinishedListener is called for both failed and succeeded uploads. If you wish to separate between these two cases, you can use SucceededListener (SucceededEvenet) and FailedListener (FailedEvent).

    The upload component does not itself show upload progress, but you can use the ProgressIndicator for providing progress feedback by implementing ProgressListener and updating the indicator in updateProgress().

    Setting upload component immediate initiates the upload as soon as a file is selected, instead of the common pattern of file selection field and upload button.

    Note! Because of browser dependent implementations of <input type="file"> element, setting size for Upload component is not supported. For some browsers setting size may work to some extend.

    Since:
    3.0
    Author:
    Vaadin Ltd.
    See Also:
    Serialized Form
    • Constructor Detail

      • Upload

        public Upload()
        Deprecated.
        Creates a new instance of Upload. The receiver must be set before performing an upload.
    • Method Detail

      • addStartedListener

        public void addStartedListener​(Upload.StartedListener listener)
        Deprecated.
        Adds the upload started event listener.
        Parameters:
        listener - the Listener to be added, not null
      • removeStartedListener

        public void removeStartedListener​(Upload.StartedListener listener)
        Deprecated.
        Removes the upload started event listener.
        Parameters:
        listener - the Listener to be removed.
      • addFinishedListener

        public void addFinishedListener​(Upload.FinishedListener listener)
        Deprecated.
        Adds the upload received event listener.
        Parameters:
        listener - the Listener to be added, not null
      • removeFinishedListener

        public void removeFinishedListener​(Upload.FinishedListener listener)
        Deprecated.
        Removes the upload received event listener.
        Parameters:
        listener - the Listener to be removed.
      • addFailedListener

        public void addFailedListener​(Upload.FailedListener listener)
        Deprecated.
        Adds the upload interrupted event listener.
        Parameters:
        listener - the Listener to be added, not null
      • removeFailedListener

        public void removeFailedListener​(Upload.FailedListener listener)
        Deprecated.
        Removes the upload interrupted event listener.
        Parameters:
        listener - the Listener to be removed.
      • addSucceededListener

        public void addSucceededListener​(Upload.SucceededListener listener)
        Deprecated.
        Adds the upload success event listener.
        Parameters:
        listener - the Listener to be added, not null
      • removeSucceededListener

        public void removeSucceededListener​(Upload.SucceededListener listener)
        Deprecated.
        Removes the upload success event listener.
        Parameters:
        listener - the Listener to be removed.
      • addProgressListener

        public void addProgressListener​(Upload.ProgressListener listener)
        Deprecated.
        Adds the upload progress event listener.
        Parameters:
        listener - the progress listener to be added
      • removeProgressListener

        public void removeProgressListener​(Upload.ProgressListener listener)
        Deprecated.
        Removes the upload progress event listener.
        Parameters:
        listener - the progress listener to be removed
      • addChangeListener

        public void addChangeListener​(Upload.ChangeListener listener)
        Deprecated.
        Adds a filename change event listener.
        Parameters:
        listener - the Listener to add, not null
      • removeChangeListener

        public void removeChangeListener​(Upload.ChangeListener listener)
        Deprecated.
        Removes a filename change event listener.
        Parameters:
        listener - the listener to be removed
      • fireStarted

        protected void fireStarted​(String filename,
                                   String mimeType)
        Deprecated.
        Emit upload received event.
        Parameters:
        filename -
        mimeType -
      • fireUploadInterrupted

        protected void fireUploadInterrupted​(String filename,
                                             String mimeType,
                                             long length)
        Deprecated.
        Emits the upload failed event.
        Parameters:
        filename -
        mimeType -
        length -
      • fireNoInputStream

        protected void fireNoInputStream​(String filename,
                                         String mimeType,
                                         long length)
        Deprecated.
      • fireNoOutputStream

        protected void fireNoOutputStream​(String filename,
                                          String mimeType,
                                          long length)
        Deprecated.
      • fireUploadInterrupted

        protected void fireUploadInterrupted​(String filename,
                                             String mimeType,
                                             long length,
                                             Exception e)
        Deprecated.
      • fireUploadSuccess

        protected void fireUploadSuccess​(String filename,
                                         String mimeType,
                                         long length)
        Deprecated.
        Emits the upload success event.
        Parameters:
        filename -
        mimeType -
        length -
      • fireUpdateProgress

        protected void fireUpdateProgress​(long totalBytes,
                                          long contentLength)
        Deprecated.
        Emits the progress event.
        Parameters:
        totalBytes - bytes received so far
        contentLength - actual size of the file being uploaded, if known
      • getReceiver

        public Upload.Receiver getReceiver()
        Deprecated.
        Returns the current receiver.
        Returns:
        the StreamVariable.
      • setReceiver

        public void setReceiver​(Upload.Receiver receiver)
        Deprecated.
        Sets the receiver.
        Parameters:
        receiver - the receiver to set.
      • startUpload

        public void startUpload()
        Deprecated.
        Go into upload state. This is to prevent double uploading on same component. Warning: this is an internal method used by the framework and should not be used by user of the Upload component. Using it results in the Upload component going in wrong state and not working. It is currently public because it is used by another class.
      • interruptUpload

        public void interruptUpload()
        Deprecated.
        Interrupts the upload currently being received. The interruption will be done by the receiving thread so this method will return immediately and the actual interrupt will happen a bit later.
      • isUploading

        public boolean isUploading()
        Deprecated.
      • getBytesRead

        public long getBytesRead()
        Deprecated.
        Gets read bytes of the file currently being uploaded.
        Returns:
        bytes
      • getUploadSize

        public long getUploadSize()
        Deprecated.
        Returns size of file currently being uploaded. Value sane only during upload.
        Returns:
        size in bytes
      • getButtonCaption

        public String getButtonCaption()
        Deprecated.
        Returns:
        String to be rendered into button that fires uploading
      • setButtonCaption

        public void setButtonCaption​(String buttonCaption)
        Deprecated.
        In addition to the actual file chooser, upload components have button that starts actual upload progress. This method is used to set text in that button.

        In case the button text is set to null, the button is hidden. In this case developer must explicitly initiate the upload process with submitUpload().

        In case the Upload is used in immediate mode using AbstractLegacyComponent.setImmediate(boolean), the file choose (html input with type "file") is hidden and only the button with this text is shown.

        Note the string given is set as is to the button. HTML formatting is not stripped. Be sure to properly validate your value according to your needs.

        Parameters:
        buttonCaption - text for upload components button.
      • submitUpload

        public void submitUpload()
        Deprecated.
        Forces the upload the send selected file to the server.

        In case developer wants to use this feature, he/she will most probably want to hide the uploads internal submit button by setting its caption to null with setButtonCaption(String) method.

        Note, that the upload runs asynchronous. Developer should use normal upload listeners to trac the process of upload. If the field is empty uploaded the file name will be empty string and file length 0 in the upload finished event.

        Also note, that the developer should not remove or modify the upload in the same user transaction where the upload submit is requested. The upload may safely be hidden or removed once the upload started event is fired.

      • getStreamVariable

        protected StreamVariable getStreamVariable()
        Deprecated.
      • isImmediate

        public boolean isImmediate()
        Deprecated.
        Returns the immediate mode of the component.

        An immediate mode Upload component displays the browser file choosing button immediately, whereas a non-immediate upload only shows a Vaadin button.

        The default mode of an Upload component is non-immediate.

        Overrides:
        isImmediate in class AbstractLegacyComponent
        Returns:
        true if the component is in immediate mode, false if the component if not in immediate mode