Documentation

Report Edit

Upload Button

import {UploadButton} from 'cx/widgets';

Upload buttons are used for selecting files and uploading them to the server.

Upload
ControllerIndex
<div class="widgets">
    <UploadButton
        icon="upload"
        url="https://api.cxjs.io/uploads"
        onUploadStarting={onUploadStarting}
        onUploadComplete={onUploadComplete}
        onUploadError={onUploadError}
    >
        Upload
    </UploadButton>
</div>
Copied!Cx Fiddle
PropertyDescriptionType
method

HTTP request method. Default value is POST.

string
multiple

Set to true to enable multiple files to be selected for upload.

boolean
onResolveUrl

A callback function used to resolve dynamic upload URLs which are sometimes necessary for cloud uploads. Arguments:

  • file - instance of the File being uploaded
  • instance - widget instance

Return value should be a string or a promise that resolves to a string.

function
onUploadComplete

A callback function called when the upload is complete. Arguments:

  • xhr - instance of the XMLHttpRequest object used for upload
  • instance - widget instance
  • file - file to be uploaded
  • formData - FormData object to be sent containing the file object

Check status and responseText of the xhr object to examine the server response.

function
onUploadError

A callback function called in case of an upload error. Arguments:

  • error - error
  • instance - widget instance
function
onUploadStarting

A callback function to validate files to be uploaded. Arguments:

  • instance - widget instance
  • xhr - instance of the XMLHttpRequest object to be used for upload
  • file - file to be uploaded
  • formData - FormData object to be sent containing the file object
function
abortOnDestroy

Set to true to abort uploads if the button is destroyed (unmounted). Default to false.

boolean
accept

Defines file types that are accepted for upload.

string
baseClass

Base CSS class to be applied to the element. Default is 'uploadbutton'.

string
disabled

Set to true to disable the button.

boolean
text

Text description.

string