public class Uploader
extends com.google.gwt.user.client.ui.AbsolutePanel
Uploader uploader = new Uploader()
.setUploadURL("http://www.widgetcorp.com/uploads.php")
.setButtonText("Click Here Yeah")
.setButtonTextStyle(".redText { color: #FF0000; }")
.setButtonWidth(100)
.setButtonHeight(22)
.setButtonCursor(Uploader.Cursor.HAND);
RootPanel.get().add(uploader);
Normally you'll also want to respond to various events that the GWT uploader component
can generate in order to notify the user about the progress and status of the uploader. E.g.
uploader.setUploadProgressHandler(new UploadProgressHandler() {
public boolean onUploadProgress(UploadProgressEvent uploadProgressEvent) {
Window.alert("File progress: " + uploadProgressEvent.getFile().getName() + "\n" +
NumberFormat.getPercentFormat().format(
uploadProgressEvent.getBytesComplete() / uploadProgressEvent.getBytesTotal()
) + " Percent Complete"
);
return true;
}
});
Similar events are available for when the file dialog window is opened, when a new file
is added to the queue, when an uploader is started/completed, when errors occur, etc.
Internally the GWT Uploader component defaults to attempting to use the browser's DOM
and XMLHttpRequest Level 2 mechanisms to manage the file selection, tracking of the various
events, and handling the uploader of the file to the server. However, some browsers don't
support the XMLHttpRequest Level 2 API (most notably of which is Internet Explorer). In
that case the uploader component automatically detects that the browser support is not
available and then transparently switches over to using a SWFUpload/Flash based
mechanism for handling the file selection and uploader process instead. More
details on the browsers which support the XMLHttpRequest Level 2 APIs can be found
here. And additional details on the SWFUpload project can be
found here. Note that if you only
want to use the SWFUpload mechanism, independent of whether or not the browser supports the
XMLHttpRequest Level 2 API, you can use the setAjaxUploadEnabled(boolean)
method
to disable the XMLHttpRequest Level 2 approach - in which case the GWT Uploader API serves
essentially as a GWT wrapper for the SWFUpload JS API.Modifier and Type | Class and Description |
---|---|
static class |
Uploader.ButtonAction
An enumeration of supported button action types, which can be passed to the
setButtonAction(ButtonAction) method. |
static class |
Uploader.Cursor
An enumeration of supported button cursor types, which can be passed to the
setButtonCursor(Cursor) method. |
static class |
Uploader.WindowMode
An enumeration of supported button window types, which can be passed to the
setButtonWindowMode(WindowMode) method. |
com.google.gwt.user.client.ui.UIObject.DebugIdImpl, com.google.gwt.user.client.ui.UIObject.DebugIdImplEnabled
Constructor and Description |
---|
Uploader()
Create a new Uploader component that can be added to a GWT application, setting up
an element in the DOM that the uploader button elements will be rendered inside of.
|
Modifier and Type | Method and Description |
---|---|
void |
addFilesToQueue(com.google.gwt.core.client.JsArray files)
When implementing drag/drop support for file uploads, this method can be used to
pass into the uploader the list of native file references that the user dropped
onto the application to be uploaded.
|
void |
cancelUpload()
Cancel the first file in the queue.
|
void |
cancelUpload(boolean triggerErrorEvent)
Cancel the first file in the queue.
|
void |
cancelUpload(String fileId)
Cancel the the file with the supplied id.
|
void |
cancelUpload(String fileId,
boolean triggerErrorEvent)
Cancel the file upload for a specific file and remove from the queue.
|
boolean |
getButtonDisabled()
Returns whether or not the button has been set in a disabled state via the
setButtonDisabled(boolean) method. |
com.google.gwt.json.client.JSONObject |
getCustomSettings()
Returns the custom settings that were stored on this uploader component instance via
the
setCustomSettings(JSONObject) method. |
static com.google.gwt.core.client.JsArray |
getDroppedFiles(com.google.gwt.dom.client.NativeEvent event)
A convenience method that can be used to extract the files that a user dropped
on the application during a GWT drop event.
|
Stats |
getStats()
Returns the overall general statistics being tracked by the Uploader component, or null
if the widget has not yet been added to the DOM.
|
static boolean |
isAjaxUploadWithProgressEventsSupported()
Returns true if the browser appears to support an HTML5 style upload (via the XMLHttpRequest Level 2
API).
|
protected void |
onLoad() |
protected void |
onUnload() |
Uploader |
setAjaxUploadEnabled(boolean ajaxUploadEnabled)
By default the component will attempt to use a DOM based Ajax uploader process if it detects
that the browser can support the necessary requirements of the "XMLHttpRequest Level 2".
|
Uploader |
setAjaxUploadURL(String ajaxUploadURL)
By default both the XMLHttpRequest Level 2/Ajax uploads and the SWFUpload/Flash uploads will
be posted to whatever URL is specified via the
setUploadURL(String) method. |
Uploader |
setAssumeSuccessTimeout(long assumeSuccessTimeout)
Convenience method for setting the 'assume_success_timeout' option of the component.
|
Uploader |
setButtonAction(Uploader.ButtonAction buttonAction)
Convenience method for setting the 'button_action' option of the component, either before or
after the widget has been added to the DOM.
|
Uploader |
setButtonCursor(Uploader.Cursor cursor)
Convenience method for setting the 'button_cursor' option of the component, either before or
after the widget has been added to the DOM.
|
Uploader |
setButtonDisabled(boolean buttonDisabled)
Convenience method for setting the 'button_disabled' option of the component, either before or
after the widget has been added to the DOM.
|
Uploader |
setButtonHeight(int buttonHeight)
Convenience method for setting the 'button_height' option of the component, either before or
after the widget has been added to the DOM.
|
Uploader |
setButtonImageURL(String buttonImageURL)
Convenience method for setting the 'button_image_url' option of the component, either before or
after the widget has been added to the DOM.
|
Uploader |
setButtonText(String buttonText)
Convenience method for setting the 'button_text' option of the component, either before or
after the widget has been added to the DOM.
|
Uploader |
setButtonTextLeftPadding(int buttonTextLeftPadding)
Convenience method for setting the 'button_text_left_padding' option of the component, either before or
after the widget has been added to the DOM.
|
Uploader |
setButtonTextStyle(String buttonTextStyle)
Convenience method for setting the 'button_text_style' option of the component, either before or
after the widget has been added to the DOM.
|
Uploader |
setButtonTextTopPadding(int buttonTextTopPadding)
Convenience method for setting the 'button_text_top_padding' option of the component, either before or
after the widget has been added to the DOM.
|
Uploader |
setButtonWidth(int buttonWidth)
Convenience method for setting the 'button_width' option of the component, either before or
after the widget has been added to the DOM.
|
Uploader |
setButtonWindowMode(Uploader.WindowMode buttonWindowMode)
Convenience method for setting the 'button_window_mode' option of the component.
|
Uploader |
setCustomSettings(com.google.gwt.json.client.JSONObject customSettings)
Convenience method for setting the 'custom_settings' option of the component.
|
Uploader |
setDebug(boolean debug)
Convenience method for setting the 'debug' option of the component.
|
Uploader |
setFileDialogCompleteHandler(FileDialogCompleteHandler fileDialogCompleteHandler)
Set a callback handler that will be invoked whenever a file dialog complete event is fired.
|
Uploader |
setFileDialogStartHandler(FileDialogStartHandler fileDialogStartHandler)
Set a callback handler that will be invoked whenever a file dialog start event is fired.
|
Uploader |
setFilePostName(String filePostName)
Convenience method for setting the 'file_post_name' option of the component, either before or
after the widget has been added to the DOM.
|
Uploader |
setFileQueuedHandler(FileQueuedHandler fileQueuedHandler)
Set a callback handler that will be invoked whenever a file queued event is fired.
|
Uploader |
setFileQueueErrorHandler(FileQueueErrorHandler fileQueueErrorHandler)
Set a callback handler that will be invoked whenever a file queue error event is fired.
|
Uploader |
setFileQueueLimit(long fileQueueLimit)
Convenience method for setting the 'file_queue_limit' option of the component, either before or
after the widget has been added to the DOM.
|
Uploader |
setFileSizeLimit(String fileSizeLimit)
Convenience method for setting the 'file_size_limit' option of the component, either before or
after the widget has been added to the DOM.
|
Uploader |
setFileTypes(String fileTypes)
Convenience method for setting the 'file_types' option of the component, either before or
after the widget has been added to the DOM.
|
Uploader |
setFileTypesDescription(String fileTypesDescription)
Convenience method for setting the 'file_types_description' option of the component, either before or
after the widget has been added to the DOM.
|
Uploader |
setFileUploadLimit(long fileUploadLimit)
Convenience method for setting the 'file_upload_limit' option of the component, either before or
after the widget has been added to the DOM.
|
Uploader |
setFlashURL(String flashURL)
Overrides the default "flash_url" setting.
|
Uploader |
setHttpSuccess(Long... httpSuccess)
Convenience method for setting the 'http_success' option of the component.
|
Uploader |
setOption(String path,
Object value)
General purpose method to set an option on the SWFUpload object at any level, using "/" characters
to designate which level of option you'd like to set.
|
Uploader |
setPostParams(com.google.gwt.json.client.JSONObject postParams)
Convenience method for setting the 'post_params' option of the component, either before or
after the widget has been added to the DOM.
|
Uploader |
setPreserveRelativeURLs(boolean preserveRelativeURLs)
Convenience method for setting the 'preserve_relative_urls' option of the component.
|
Uploader |
setPreventSWFCaching(boolean preventSWFCaching)
Convenience method for setting the 'prevent_swf_caching' option of the component.
|
Uploader |
setRequeueOnError(boolean requeueOnError)
Convenience method for setting the 'requeue_on_error' option of the component.
|
Uploader |
setSWFUploadLoadedHandler(SWFUploadLoadedHandler swfUploadLoadedHandler)
Set a callback handler that will be invoked whenever a Uploader loaded event is fired.
|
Uploader |
setUploadCompleteHandler(UploadCompleteHandler uploadCompleteHandler)
Set a callback handler that will be invoked whenever an uploader complete event is fired.
|
Uploader |
setUploadErrorHandler(UploadErrorHandler uploadErrorHandler)
Set a callback handler that will be invoked whenever an uploader error event is fired.
|
Uploader |
setUploadProgressHandler(UploadProgressHandler uploadProgressHandler)
Set a callback handler that will be invoked whenever an uploader progress event is fired.
|
Uploader |
setUploadStartHandler(UploadStartHandler uploadStartHandler)
Set a callback handler that will be invoked whenever an uploader start event is fired.
|
Uploader |
setUploadSuccessHandler(UploadSuccessHandler uploadSuccessHandler)
Set a callback handler that will be invoked whenever an uploader success event is fired.
|
Uploader |
setUploadURL(String uploadURL)
Convenience method for setting the 'upload_url' option of the component, either before or
after the widget has been added to the DOM.
|
Uploader |
setUseQueryString(boolean useQueryString)
Convenience method for setting the 'use_query_string' option of the component, either before or
after the widget has been added to the DOM.
|
void |
startUpload()
Cause the first file in the queue to start the uploader process
|
void |
startUpload(String fileId)
Cause the file with the specified Id to start the uploader process.
|
add, add, add, getWidgetLeft, getWidgetTop, insert, insert, insert, remove, setWidgetPosition, setWidgetPositionImpl
add, adjustIndex, checkIndexBoundsForAccess, checkIndexBoundsForInsertion, getChildren, getWidget, getWidgetCount, getWidgetIndex, getWidgetIndex, insert, insert, iterator, remove
add, adopt, adopt, clear, disown, doAttachChildren, doDetachChildren, orphan, remove
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, fireEvent, getHandlerCount, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onBrowserEvent, onDetach, removeFromParent, setLayoutData, sinkEvents
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString, unsinkEvents
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public Uploader()
public Uploader setUploadURL(String uploadURL)
uploader.setOption("upload_url", "http://www.widgetcorp.com/uploads.php");
The upload_url setting accepts a full, absolute, or relative target URL for the uploaded file.
Relative URLs should be relative to the document. The upload_url should be in the same domain
as the SWFUploader Flash Control for best compatibility in browsers that don't support the
XMLHttpRequest Level 2 API.
In the case that the SWFUpload/Flash control is used if the setPreserveRelativeURLs(boolean)
setting is false (the default) Uploader will convert the relative URL to an absolute URL to avoid the
URL being interpreted differently by the Flash Player on different platforms. If you disable
SWFUploads conversion of the URL relative URLs should be relative to the uploader.swf file.
By default both the XMLHttpRequest Level 2/Ajax uploads and the SWFUpload/Flash uploads will
be posted to whatever URL is specified via this method.
However, if you'd like the Ajax uploads to be posted to a different URL than the SWF
uploads, you can call the setAjaxUploadURL(String)
method to set a unique URL
for the Ajax uploads (and then only the SWF uploads will use the general "uploadURL").uploadURL
- The value to set as the 'upload_url' option on the Uploader component.Uploader
instance for convenient method chaining.public Uploader setAjaxUploadURL(String ajaxUploadURL)
setUploadURL(String)
method.
However, if you'd like the Ajax uploads to be posted to a different URL than the SWF
uploads, you can call this method to set a unique URL for the Ajax uploads (and then
only the SWF uploads will use the general "uploadURL").ajaxUploadURL
- The URL that only the Ajax uploads should be posted to (or null
to uploader both the Ajax and SWF uploads to whatever
the setUploadURL(String)
option has been set to.)Uploader
instance for convenient method chaining.public Uploader setAjaxUploadEnabled(boolean ajaxUploadEnabled)
ajaxUploadEnabled
- By default ajax uploader is enabled and will be used as long as the
browser supports the "XMLHttpRequest Level 2" object. Setting this option
to "false" will instead force the component to avoid using the Ajax
approach and instead utilize the SWFUpload/Flash technique only.Uploader
instance for convenient method chaining.public Uploader setFilePostName(String filePostName)
uploader.setOption("file_post_name", "Filedata");
The file_post_name allows you to set the value name used to post the file. This is not related
to the file name. The default value is 'Filedata'. For maximum compatibility it is recommended
that the default value is used.filePostName
- The value to set as the 'file_post_name' option on the Uploader component.Uploader
instance for convenient method chaining.public Uploader setPostParams(com.google.gwt.json.client.JSONObject postParams)
JSONObject params = new JSONObject();
params.put("post_param_name_1", new JSONString("post_param_value_1"));
params.put("post_param_name_2", new JSONString("post_param_value_2"));
params.put("post_param_name_n", new JSONString("post_param_value_n"));
uploader.setOption("post_params", params);
The post_params setting defines the name/value pairs that will be posted with each uploaded file.
This setting accepts a simple JavaScript object. Multiple post name/value pairs should be defined
as demonstrated in the sample settings object. Values must be either strings or numbers
(as interpreted by the JavaScript typeof function).
Note: Flash Player 8 does not support sending additional post parameters. SWFUpload will
automatically send the post_params as part of the query string.
postParams
- The value to set as the 'post_params' option on the Uploader component.Uploader
instance for convenient method chaining.public Uploader setUseQueryString(boolean useQueryString)
uploader.setOption("use_query_string", false);
The use_query_string setting may be true or false. This value indicates whether Uploader
should send the post_params and file params on the query string or the post.
Note that this option only applies when the SWFUpload/Flash component is rendered. When
the DHTML/Ajax mode is being used (the default) the params are always passed as
part of the post.useQueryString
- The value to set as the 'use_query_string' option on the Uploader component.Uploader
instance for convenient method chaining.public Uploader setPreserveRelativeURLs(boolean preserveRelativeURLs)
uploader.setOption("preserve_relative_urls", false);
A boolean value that indicates whether Uploader should attempt to convert relative URLs used
by the Flash Player to absolute URLs. If set to true Uploader will not modify any URLs.
The default value is false.
Note that this option only applies when the SWFUpload/Flash component is rendered.preserveRelativeURLs
- The value to set as the 'preserve_relative_urls' option on the Uploader component.Uploader
instance for convenient method chaining.public Uploader setRequeueOnError(boolean requeueOnError)
uploader.setOption("requeue_on_error", true);
The requeue_on_error setting may be true or false. When this setting is true any files that
has an uploadError (excluding fileQueue errors and the FILE_CANCELLED uploadError) is
returned to the front of the queue rather than being discarded. The file can be uploaded
again if needed. To remove the file from the queue the cancelUpload method must be called.
All the events associated with a failed uploader are still called and so the requeuing the
failed uploader can conflict with the Queue Plugin (or custom code that uploads the entire
queue). Code that automatically uploads the next file in the queue will uploader the failed
file over and over again if care is not taken to allow the failing uploader to be cancelled.requeueOnError
- The value to set as the 'requeue_on_error' option on the Uploader component (default: false).Uploader
instance for convenient method chaining.public Uploader setHttpSuccess(Long... httpSuccess)
uploader.setOption("http_success", new Long[] { 200L, 203L });
An array that defines the HTTP Status Codes that will trigger success. 200 is always a success.
Also, only the 200 status code provides the serverData.
When returning and accepting an HTTP Status Code other than 200 it is not necessary for the
server to return content.httpSuccess
- The values to set as the HTTP response codes to treat as a successful response (default: 200).Uploader
instance for convenient method chaining.public Uploader setAssumeSuccessTimeout(long assumeSuccessTimeout)
uploader.setOption("assume_success_timeout", 1000);
The number of seconds SWFUpload should wait for Flash to detect the server's response after
the file has finished uploading. This setting allows you to work around the Flash Player
bugs where long running server side scripts causes Flash to ignore the server response
or the Mac Flash Player bug that ignores server responses with no content.
Testing has shown that Flash will ignore server responses that take longer than 30 seconds
after the last uploadProgress event.
A timeout of zero (0) seconds disables this feature and is the default value. SWFUpload will
wait indefinitely for the Flash Player to trigger the uploadSuccess event.
Note that this option only applies when the SWFUpload/Flash component is rendered.assumeSuccessTimeout
- The value to set as the 'assume_success_timeout' option on the Uploader component.Uploader
instance for convenient method chaining.public Uploader setFileTypes(String fileTypes)
uploader.setOption("file_types", "*.jpg;*.gif");
The file_types setting accepts a semi-colon separated list of file extensions that are
allowed to be selected by the user. Use '*.*' to allow all file types.fileTypes
- A semi-colon delimited list of file types that the file dialog should allow
the user to select.Uploader
instance for convenient method chaining.public Uploader setFileTypesDescription(String fileTypesDescription)
uploader.setOption("file_types_description", "Web Photos");
A text description that is displayed to the user in the File Browser dialog.fileTypesDescription
- A text description that is displayed to the user in the File Browser dialog.Uploader
instance for convenient method chaining.public Uploader setFileSizeLimit(String fileSizeLimit)
uploader.setOption("file_size_limit", "5 MB");
The file_size_limit setting defines the maximum allowed size of a file to be uploaded.
This setting accepts a value and unit. Valid units are B, KB, MB and GB.
Examples: 2147483648 B, 2097152, 2097152KB, 2048 MB, 2 GB
If the unit is omitted default is KB. A value of 0 (zero) is interpreted as unlimited.
Note: This setting only applies to the user's browser. It does not affect any settings or
limits on the web server.fileSizeLimit
- The maximum allowed size of a file to be uploaded.Uploader
instance for convenient method chaining.public Uploader setFileUploadLimit(long fileUploadLimit)
uploader.setOption("file_upload_limit", 10);
Defines the number of files allowed to be uploaded by the uploader component. This setting also sets the
upper bound of the file_queue_limit setting. Once the user has uploaded or queued the maximum
number of files she will no longer be able to queue additional files. The value of 0 (zero)
is interpreted as unlimited. Only successful uploads (uploads the trigger the uploadSuccess
event) are counted toward the uploader limit.
Note: This value is not tracked across pages and is reset when a page is refreshed. File quotas
should be managed by the web server.fileUploadLimit
- The number of files allowed to be uploaded by the uploader component.Uploader
instance for convenient method chaining.public Uploader setFileQueueLimit(long fileQueueLimit)
uploader.setOption("file_queue_limit", 10);
Defines the number of unprocessed files allowed to be simultaneously queued. Once a file is
uploaded, errored, or cancelled new files can be queued in its place until the queue limit
has been reached. If the uploader limit (or remaining uploads allowed) is less than the queue
limit then the lower number is used.fileQueueLimit
- The number of unprocessed files allowed to be simultaneously queued.Uploader
instance for convenient method chaining.public Uploader setFlashURL(String flashURL)
flashURL
- The value to set as the 'flash_url' option on the Uploader component.Uploader
instance for convenient method chaining.public Uploader setPreventSWFCaching(boolean preventSWFCaching)
uploader.setOption("prevent_swf_caching", false);
This boolean setting indicates whether a random value should be added to the Flash URL in an
attempt to prevent the browser from caching the SWF movie. This works around a bug in
some IE-engine based browsers.
Note: The algorithm for adding the random number to the URL is dumb and cannot handle
URLs that already have some parameters.
Note that this option only applies when the SWFUpload/Flash component is rendered.preventSWFCaching
- The value to set as the 'prevent_swf_caching' option on the Uploader component.Uploader
instance for convenient method chaining.public Uploader setDebug(boolean debug)
uploader.setOption("debug", false);
A boolean value that defines whether the debug event handler should be fired.
Note that this option only applies when the SWFUpload/Flash component is rendered.debug
- The value to set as the 'debug' option on the Uploader component.Uploader
instance for convenient method chaining.public Uploader setButtonImageURL(String buttonImageURL)
uploader.setOption("button_image_url", "http://widgetcorp.com/upload_button.png");
Fully qualified, absolute or relative URL to the image file to be used as the button's image.
This URL is affected by the preserve_relative_urls setting and should follow the same
rules as the upload_url setting.
The button image is treated as a sprite. There are 4 button states that must be represented
by the button image. Each button state image should be stacked above the other in this
order: normal, hover, down/click, disabled.buttonImageURL
- The URL to the image file to be used as the button's image.Uploader
instance for convenient method chaining.public Uploader setButtonWidth(int buttonWidth)
uploader.setOption("button_width", 62);
A number defining the width of the uploader button.buttonWidth
- The value to set as width of the uploader button.Uploader
instance for convenient method chaining.public Uploader setButtonHeight(int buttonHeight)
uploader.setOption("button_height", 21);
A number defining the height of the uploader button.buttonHeight
- The value to set as height of the uploader button.Uploader
instance for convenient method chaining.public Uploader setButtonText(String buttonText)
uploader.setOption("button_text", "Click here");
Plain or HTML text that is displayed over the uploader button. HTML text can be further styled
using CSS classes and the button_text_style setting, but should be limited to what Flash
can support for compatibility with browsers that don't support the XMLHttpRequest Level 2 API. See
Adobe's Flash documentation
for details.buttonText
- Plain or HTML text that is displayed over the uploader button.Uploader
instance for convenient method chaining.public Uploader setButtonTextStyle(String buttonTextStyle)
uploader.setOption("button_text_style", ".redText { color: #FF0000; }");
CSS style string that defines how the button_text is displayed. Should be limited to what Flash
can support for compatibility with browsers that don't support the XMLHttpRequest Level 2 API. See
Adobe's Flash documentation
for details.buttonTextStyle
- The CSS style string that defines how the button text is displayed.Uploader
instance for convenient method chaining.public Uploader setButtonTextTopPadding(int buttonTextTopPadding)
uploader.setOption("button_text_top_padding", 2);
Used to vertically position the button text within the uploader component. Negative values may be used.buttonTextTopPadding
- The amount of padding to include between the outer bounds of the uploader
component and the top of the text.Uploader
instance for convenient method chaining.public Uploader setButtonTextLeftPadding(int buttonTextLeftPadding)
uploader.setOption("button_text_left_padding", 2);
Used to horizontally position the button text within the uploader component. Negative values may be used.buttonTextLeftPadding
- The amount of padding to include between the outer bounds of the uploader
component and the left of the text.Uploader
instance for convenient method chaining.public Uploader setButtonAction(Uploader.ButtonAction buttonAction)
uploader.setOption("button_action", ButtonAction.SELECT_FILES);
Defines the action to take when the uploader component is clicked.buttonAction
- The action to take when the uploader component is clicked.Uploader
instance for convenient method chaining.public Uploader setButtonDisabled(boolean buttonDisabled)
uploader.setOption("button_disabled", false);
A boolean value that sets whether the uploader button is in the disabled state. When in the
disabled state the button will not execute any actions.buttonDisabled
- Whether the uploader button is in the disabled state.Uploader
instance for convenient method chaining.public boolean getButtonDisabled()
setButtonDisabled(boolean)
method.public Uploader setButtonCursor(Uploader.Cursor cursor)
uploader.setOption("button_cursor", Cursor.HAND);
Used to define what type of mouse cursor is displayed when hovering over the uploader component.cursor
- The type of cursor to display when the mouse is hovering over the uploader component.Uploader
instance for convenient method chaining.public Uploader setButtonWindowMode(Uploader.WindowMode buttonWindowMode)
uploader.setOption("button_window_mode", WindowMode.TRANSPARENT);
Sets the WMODE property of the Flash Movie.
Note that this option only applies when the SWFUpload/Flash component is rendered.buttonWindowMode
- The value to set as the 'button_window_mode' option on the Uploader component.Uploader
instance for convenient method chaining.public Uploader setCustomSettings(com.google.gwt.json.client.JSONObject customSettings)
JSONObject settings = new JSONObject();
settings.put("My Setting", new JSONString("This is my setting"));
settings.put("myothersetting", new JSONString("This is my other setting"));
settings.put("integer_setting", new JSONNumber(100));
uploader.setOption("custom_settings", settings);
The custom_settings setting allows developers to safely attach additional information to a
uploader instance without worrying about affecting internal values or changes
in new GWT Uploader (or SWFUpload) versions. This setting accepts a JSON object.
Once instantiated the custom settings are accessed via the getCustomSettings()
method.customSettings
- The value to set as the 'custom_settings' option on the uploader component.Uploader
instance for convenient method chaining.public com.google.gwt.json.client.JSONObject getCustomSettings()
setCustomSettings(JSONObject)
method. The custom_settings setting allows
developers to safely attach additional information to a uploader instance without worrying
about affecting internal values or changes in new GWT Uploader (or SWFUpload) versions.public Stats getStats()
public Uploader setSWFUploadLoadedHandler(SWFUploadLoadedHandler swfUploadLoadedHandler)
swfUploadLoadedHandler
- The handler that should be invoked whenever a Uploader loaded event occurs.Uploader
instance for convenient method chaining.public Uploader setFileDialogStartHandler(FileDialogStartHandler fileDialogStartHandler)
fileDialogStartHandler
- The handler that should be invoked whenever a file dialog start event occurs.Uploader
instance for convenient method chaining.public Uploader setFileQueuedHandler(FileQueuedHandler fileQueuedHandler)
fileQueuedHandler
- The handler that should be invoked whenever a file queued event occurs.Uploader
instance for convenient method chaining.public Uploader setFileQueueErrorHandler(FileQueueErrorHandler fileQueueErrorHandler)
fileQueueErrorHandler
- The handler that should be invoked whenever a file queue error event occurs.Uploader
instance for convenient method chaining.public Uploader setFileDialogCompleteHandler(FileDialogCompleteHandler fileDialogCompleteHandler)
fileDialogCompleteHandler
- The handler that should be invoked whenever a file dialog complete event occurs.Uploader
instance for convenient method chaining.public Uploader setUploadCompleteHandler(UploadCompleteHandler uploadCompleteHandler)
uploadCompleteHandler
- The handler that should be invoked whenever an uploader complete event occurs.Uploader
instance for convenient method chaining.public Uploader setUploadErrorHandler(UploadErrorHandler uploadErrorHandler)
uploadErrorHandler
- The handler that should be invoked whenever an uploader error event occurs.Uploader
instance for convenient method chaining.public Uploader setUploadProgressHandler(UploadProgressHandler uploadProgressHandler)
uploadProgressHandler
- The handler that should be invoked whenever an uploader progress event occurs.Uploader
instance for convenient method chaining.public Uploader setUploadStartHandler(UploadStartHandler uploadStartHandler)
uploadStartHandler
- The handler that should be invoked whenever an uploader start event occurs.Uploader
instance for convenient method chaining.public Uploader setUploadSuccessHandler(UploadSuccessHandler uploadSuccessHandler)
uploadSuccessHandler
- The handler that should be invoked whenever an uploader success event occurs.Uploader
instance for convenient method chaining.public Uploader setOption(String path, Object value)
Uploader uploader = new Uploader();
uploader.setOption("/upload_url", "http://widgetcorp.com/uploads.php");
uploader.setOption("/post_params/upload_type", "Photo Upload");
uploader.setOption("/post_params/user_id", "User 24");
Would result in initializing the SWFUpload component like the following:
new SWFUpload({
upload_url: "http://widgetcorp.com/uploads.php",
post_params: {
upload_type: "Photo Upload",
user_id: "User 24"
}
});
Note that the beginning "/" is optional, so uploader.setOption("/thing", "piglet")
is
equivalent to uploader.setOption("thing", "piglet")
.
For details on available options see the SWFUpload reference.
Important note: this method is only intended to support additional options of the SWFUpload API
that may not have explicit wrapper methods available in the GWT Uploader API. For all of the standard
configuration options it is important to use the appropriate setter methods instead in order
for the Ajax/DOM implementation to function properly as well. E.g. instead of doing this:
uploader.setOption("upload_url", "http://widgetcorp.com/uploads.php");
Do this instead:
uploader.setUploadURL("http://widgetcorp.com/uploads.php");
path
- The path to the option to set (e.g. "/title/text");value
- The value to set for the option (can be a String, Number, Boolean, or JSONObject)Uploader
instance for convenient method chaining.public void startUpload()
public void startUpload(String fileId)
fileId
- The id of the file the begin uploadingpublic void cancelUpload(String fileId, boolean triggerErrorEvent)
fileId
- The fileId to canceltriggerErrorEvent
- if true, an uploadError event will be issuedpublic void cancelUpload()
public void cancelUpload(String fileId)
fileId
- The fileId to cancelpublic void cancelUpload(boolean triggerErrorEvent)
triggerErrorEvent
- if true, an uploadError event will be issuedpublic static boolean isAjaxUploadWithProgressEventsSupported()
protected void onLoad()
onLoad
in class com.google.gwt.user.client.ui.Widget
public void addFilesToQueue(com.google.gwt.core.client.JsArray files)
getDroppedFiles(com.google.gwt.dom.client.NativeEvent)
method. E.g.
final Uploader uploader = new Uploader();
dropFilesArea.addDropHandler(new DropHandler() {
public void onDrop(DropEvent event) {
event.preventDefault();
uploader.addFilesToQueue(
Uploader.getDroppedFiles(event.getNativeEvent())
);
}
});
files
- An array of native file references to be added to the queue.public static com.google.gwt.core.client.JsArray getDroppedFiles(com.google.gwt.dom.client.NativeEvent event)
final Uploader uploader = new Uploader();
dropFilesArea.addDropHandler(new DropHandler() {
public void onDrop(DropEvent event) {
event.preventDefault();
uploader.addFilesToQueue(
Uploader.getDroppedFiles(event.getNativeEvent())
);
}
});
event
- The native event provided by GWT that was fired when the drop occurredaddFileToQueue(com.google.gwt.core.client.JavaScriptObject)
method.protected void onUnload()
onUnload
in class com.google.gwt.user.client.ui.Widget
Copyright © 2016. All Rights Reserved.