plupload.Uploader

Namespace plupload
Class Uploader
Uploader class, an instance of this class will be created for each upload field.

Example

var uploader = new plupload.Uploader({
    runtimes : 'gears,html5,flash',
    browse_button : 'button_id'
});

uploader.bind('Init', function(up) {
    alert('Supports drag/drop: ' + (!!up.features.dragdrop));
});

uploader.bind('FilesAdded', function(up, files) {
    alert('Selected files: ' + files.length);
});

uploader.bind('QueueChanged', function(up) {
    alert('Queued files: ' + uploader.files.length);
});

uploader.init();

Public Properties

Property Defined By
features : Object
Map of features that are available for the uploader runtime.
Uploader
files : Array
Current upload queue, an array of File instances.
Uploader
id : String
Unique id for the Uploader instance.
Uploader
runtime : String
Current runtime name.
Uploader
settings : Object
Object with name/value settings.
Uploader
state : Number
Current state of the total uploading progress.
Uploader
Total progess information.
Uploader

Public Methods

Method Defined By
Uploader(settings:Object)
Constructs a new uploader instance.
Uploader
bind(name:String, func:function, scope:Object):void
Adds an event listener by name.
Uploader
destroy():void
Destroys Plupload instance and cleans after itself.
Uploader
getFile(id:String):File
Returns the specified file object by id.
Uploader
init():void
Initializes the Uploader instance and adds internal event listeners.
Uploader
refresh():void
Refreshes the upload instance by dispatching out a refresh event to all runtimes.
Uploader
removeFile(file:File):void
Removes a specific file.
Uploader
splice(start:Number, length:Number):Array
Removes part of the queue and returns the files removed.
Uploader
start():void
Starts uploading the queued files.
Uploader
stop():void
Stops the upload of the queued files.
Uploader
trigger(name:String, Multiple:Object..):void
Dispatches the specified event name and it's arguments to all listeners.
Uploader
unbind(name:String, func:function):void
Removes the specified event listener.
Uploader
unbindAll():void
Removes all event listeners.
Uploader

Public Events

Event Defined By
BeforeUpload(uploader:Uploader, file:File)
Fires when just before a file is uploaded.
Uploader
ChunkUploaded(uploader:Uploader, file:File, response:Object)
Fires when file chunk is uploaded.
Uploader
Destroy(uploader:Uploader)
Fires when destroy method is called.
Uploader
Error(uploader:Uploader, error:Object)
Fires when a error occurs.
Uploader
FilesAdded(uploader:Uploader, files:Array)
Fires while when the user selects files to upload.
Uploader
FilesRemoved(uploader:Uploader, files:Array)
Fires while a file was removed from queue.
Uploader
FileUploaded(uploader:Uploader, file:File, response:Object)
Fires when a file is successfully uploaded.
Uploader
Init(uploader:Uploader)
Fires when the current RunTime has been initialized.
Uploader
PostInit(uploader:Uploader)
Fires after the init event incase you need to perform actions there.
Uploader
Fires when the file queue is changed.
Uploader
Refresh(uploader:Uploader)
Fires when the silverlight/flash or other shim needs to move.
Uploader
Fires when the overall state is being changed for the upload queue.
Uploader
UploadComplete(uploader:Uploader, files:Array)
Fires when all files in a queue are uploaded.
Uploader
UploadFile(uploader:Uploader, file:File)
Fires when a file is to be uploaded by the runtime.
Uploader
UploadProgress(uploader:Uploader, file:File)
Fires while a file is being uploaded.
Uploader

Property details

featuresproperty

public features : Object
Map of features that are available for the uploader runtime. Features will be filled before the init event is called, these features can then be used to alter the UI for the end user. Some of the current features that might be in this map is: dragdrop, chunks, jpgresize, pngresize.

filesproperty

public files : Array
Current upload queue, an array of File instances.

See Also

idproperty

public id : String
Unique id for the Uploader instance.

runtimeproperty

public runtime : String
Current runtime name.

settingsproperty

public settings : Object
Object with name/value settings.

stateproperty

public state : Number
Current state of the total uploading progress. This one can either be plupload.STARTED or plupload.STOPPED. These states are controlled by the stop/start methods. The default value is STOPPED.

totalproperty

public total : QueueProgress
Total progess information. How many files has been uploaded, total percent etc.

Method details

Uploaderconstructor

public function Uploader(settings:Object)
Constructs a new uploader instance.

Parameters

settings:Object Initialization settings, to be used by the uploader instance and runtimes.

bindmethod

public function bind(name:String, func:function, scope:Object):void
Adds an event listener by name.

Parameters

name:String Event name to listen for.
func:function Function to call ones the event gets fired.
scope:Object Optional scope to execute the specified function in.

destroymethod

public function destroy():void
Destroys Plupload instance and cleans after itself.

getFilemethod

public function getFile(id:String):File
Returns the specified file object by id.

Parameters

id:String File id to look for.

Returns

File - File object or undefined if it wasn't found;

initmethod

public function init():void
Initializes the Uploader instance and adds internal event listeners.

refreshmethod

public function refresh():void
Refreshes the upload instance by dispatching out a refresh event to all runtimes. This would for example reposition flash/silverlight shims on the page.

removeFilemethod

public function removeFile(file:File):void
Removes a specific file.

Parameters

file:File File to remove from queue.

splicemethod

public function splice(start:Number, length:Number):Array
Removes part of the queue and returns the files removed. This will also trigger the FilesRemoved and QueueChanged events.

Parameters

start:Number (Optional) Start index to remove from.
length:Number (Optional) Lengh of items to remove.

Returns

Array - Array of files that was removed.

startmethod

public function start():void
Starts uploading the queued files.

stopmethod

public function stop():void
Stops the upload of the queued files.

triggermethod

public function trigger(name:String, Multiple:Object..):void
Dispatches the specified event name and it's arguments to all listeners.

Parameters

name:String Event name to fire.
Multiple:Object.. arguments to pass along to the listener functions.

unbindmethod

public function unbind(name:String, func:function):void
Removes the specified event listener.

Parameters

name:String Name of event to remove.
func:function Function to remove from listener.

unbindAllmethod

public function unbindAll():void
Removes all event listeners.

Event details

BeforeUploadevent

public event BeforeUpload(uploader:Uploader, file:File)
Fires when just before a file is uploaded. This event enables you to override settings on the uploader instance before the file is uploaded.

Parameters

uploader:Uploader Uploader instance sending the event.
file:File File to be uploaded.

ChunkUploadedevent

public event ChunkUploaded(uploader:Uploader, file:File, response:Object)
Fires when file chunk is uploaded.

Parameters

uploader:Uploader Uploader instance sending the event.
file:File File that the chunk was uploaded for.
response:Object Object with response properties.

Destroyevent

public event Destroy(uploader:Uploader)
Fires when destroy method is called.

Parameters

uploader:Uploader Uploader instance sending the event.

Errorevent

public event Error(uploader:Uploader, error:Object)
Fires when a error occurs.

Parameters

uploader:Uploader Uploader instance sending the event.
error:Object Contains code, message and sometimes file and other details.

FilesAddedevent

public event FilesAdded(uploader:Uploader, files:Array)
Fires while when the user selects files to upload.

Parameters

uploader:Uploader Uploader instance sending the event.
files:Array Array of file objects that was added to queue/selected by the user.

FilesRemovedevent

public event FilesRemoved(uploader:Uploader, files:Array)
Fires while a file was removed from queue.

Parameters

uploader:Uploader Uploader instance sending the event.
files:Array Array of files that got removed.

FileUploadedevent

public event FileUploaded(uploader:Uploader, file:File, response:Object)
Fires when a file is successfully uploaded.

Parameters

uploader:Uploader Uploader instance sending the event.
file:File File that was uploaded.
response:Object Object with response properties.

Initevent

public event Init(uploader:Uploader)
Fires when the current RunTime has been initialized.

Parameters

uploader:Uploader Uploader instance sending the event.

PostInitevent

public event PostInit(uploader:Uploader)
Fires after the init event incase you need to perform actions there.

Parameters

uploader:Uploader Uploader instance sending the event.

QueueChangedevent

public event QueueChanged(uploader:Uploader)
Fires when the file queue is changed. In other words when files are added/removed to the files array of the uploader instance.

Parameters

uploader:Uploader Uploader instance sending the event.

Refreshevent

public event Refresh(uploader:Uploader)
Fires when the silverlight/flash or other shim needs to move.

Parameters

uploader:Uploader Uploader instance sending the event.

StateChangedevent

public event StateChanged(uploader:Uploader)
Fires when the overall state is being changed for the upload queue.

Parameters

uploader:Uploader Uploader instance sending the event.

UploadCompleteevent

public event UploadComplete(uploader:Uploader, files:Array)
Fires when all files in a queue are uploaded.

Parameters

uploader:Uploader Uploader instance sending the event.
files:Array Array of file objects that was added to queue/selected by the user.

UploadFileevent

public event UploadFile(uploader:Uploader, file:File)
Fires when a file is to be uploaded by the runtime.

Parameters

uploader:Uploader Uploader instance sending the event.
file:File File to be uploaded.

UploadProgressevent

public event UploadProgress(uploader:Uploader, file:File)
Fires while a file is being uploaded. Use this event to update the current file upload progress.

Parameters

uploader:Uploader Uploader instance sending the event.
file:File File that is currently being uploaded.