Class WFileDropWidget

public class WFileDropWidget extends WContainerWidget
A widget that allows dropping files for upload.

This widget accepts files that are dropped into it. A signal is triggered whenever one or more files are dropped. The filename, type and size of these files is immediately available through the WFileDropWidget.File interface.

The file upload is done sequentially. All files before the getCurrentIndex() have either finished, failed or have been cancelled.

The widget has the default style-class 'Wt-filedropzone'. The style-class 'Wt-dropzone-hover' is added when files are hovered over the widget.

  • Constructor Details

  • Method Details

    • getUploads

      public List<WFileDropWidget.File> getUploads()
      Returns the vector of uploads managed by this widget.

      The files in this vector are handled sequentially by the widget. All WFileDropWidget.File objects in this vector have either finished or failed if they are before the getCurrentIndex(), depending on the return value of isUploadFinished(). The other files are still being handled.

      Remark: Since version 4.7.0, this method returns a copy of the vector because we changed the internal vector to hold values of type std::unique_ptr.

      See Also:
    • getCurrentIndex

      public int getCurrentIndex()
      Return the index of the file that is currently being handled.

      If nothing is to be done, this will return the size of the vector returned by getUploads().

    • cancelUpload

      public void cancelUpload(WFileDropWidget.File file)
      Cancels the upload of a file.

      If you cancel a file that is still waiting to be uploaded, it will stay in the getUploads() vector, but it will be skipped.

    • remove

      public boolean remove(WFileDropWidget.File file)
      Removes the file.

      This can be used to free resources of files that were already uploaded. A file can only be removed if its index in getUploads() is before the current index.

    • setAcceptDrops

      public void setAcceptDrops(boolean enable)
      When set to false, the widget no longer accepts any files.
    • setHoverStyleClass

      public void setHoverStyleClass(String className)
      Override the css rule '.Wt-filedropzone.Wt-dropzone-hover' instead.
      Set the style class that is applied when a file is hovered over the widget.

    • setFilters

      public void setFilters(String acceptAttributes)
      Sets input accept attributes.

      The accept attribute may be specified to provide user agents with a hint of what file types will be accepted. Use html input accept attributes as input. This only affects the popup that is shown when users click on the widget. A user can still drop any file type.

    • setDropIndicationEnabled

      public void setDropIndicationEnabled(boolean enable)
      Highlight widget if a file is dragged anywhere on the page.

      As soon as a drag enters anywhere on the page the styleclass 'Wt-dropzone-indication' is added to this widget. This can be useful to point the user to the correct place to drop the file. Once the user drags a file over the widget itself, the styleclass 'hover-style' is also added. This can be enabled for multiple dropwidgets if only one of them is visible at the same time.

      See Also:
    • isDropIndicationEnabled

      public boolean isDropIndicationEnabled()
      Returns if the widget is highlighted for drags anywhere on the page.

      See Also:
    • setGlobalDropEnabled

      public void setGlobalDropEnabled(boolean enable)
      Allow dropping the files anywhere on the page.

      If enabled, a drop anywhere on the page will be forwarded to this widget.

      See Also:
    • isGlobalDropEnabled

      public boolean isGlobalDropEnabled()
      Returns if all drops are forwarded to this widget.

      See Also:
    • setJavaScriptFilter

      public void setJavaScriptFilter(String filterFn, long chunksize, List<String> imports)
      Supply a function to process file data before it is uploaded to the server.
    • setJavaScriptFilter

      public final void setJavaScriptFilter(String filterFn)
      Supply a function to process file data before it is uploaded to the server.

      Calls setJavaScriptFilter(filterFn, 0, new ArrayList())

    • setJavaScriptFilter

      public final void setJavaScriptFilter(String filterFn, long chunksize)
      Supply a function to process file data before it is uploaded to the server.

      Calls setJavaScriptFilter(filterFn, chunksize, new ArrayList())

    • drop

      The signal triggers if one or more files are dropped.
    • newUpload

      public Signal1<WFileDropWidget.File> newUpload()
      The signal triggers when the upload of a file is about to begin.

      After this signal is triggered, the upload automatically starts. The upload can still fail if the file is too large or if there is a network error.

    • uploaded

      public Signal1<WFileDropWidget.File> uploaded()
      The signal is triggered if any file finished uploading.
    • tooLarge

      public Signal2<WFileDropWidget.File,Long> tooLarge()
      The signal triggers when a file is too large for upload.

      This signal is triggered when the widget attempts to upload the file.

      The second argument is the size of the file in bytes.

    • uploadFailed

      public Signal1<WFileDropWidget.File> uploadFailed()
      The signal triggers when an upload failed.

      This signal will trigger when the widget skips over one of the files in the list for an unknown reason (e.g. happens when you drop a folder).

    • enableAjax

      protected void enableAjax()
      Description copied from class: WWidget
      Progresses to an Ajax-enabled widget.

      This method is called when the progressive bootstrap method is used, and support for AJAX has been detected. The default behavior will upgrade the widget's event handling to use AJAX instead of full page reloads, and propagate the call to its children.

      You may want to reimplement this method if you want to make changes to widget when AJAX is enabled. You should always call the base implementation.

      enableAjax in class WWebWidget
      See Also: