从官网中复制部分API,方便今后查看。
plupload.Uploader
Namespace | plupload |
Class | Uploader |
Uploader class, an instance of this class will be created for each upload field.
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 |
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 |
---|---|
Fires when just before a file is uploaded.
| Uploader |
Fires when file chunk is uploaded.
| Uploader |
Fires when destroy method is called.
| Uploader |
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 |
Fires when a file is successfully uploaded.
| Uploader |
Fires when the current RunTime has been initialized.
| Uploader |
Fires after the init event incase you need to perform actions there.
| Uploader |
QueueChanged(uploader:
Uploader)
Fires when the file queue is changed.
| Uploader |
Fires when the silverlight/flash or other shim needs to move.
| Uploader |
StateChanged(uploader:
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 |
Fires when a file is to be uploaded by the runtime.
| Uploader |
Fires while a file is being uploaded.
| Uploader |
Property details
features property
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.
id property
public id : String
Unique id for the Uploader instance.
runtime property
public runtime : String
Current runtime name.
settings property
public settings : Object
Object with name/value settings.
state property
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.
total property
public total : QueueProgress
Total progess information. How many files has been uploaded, total percent etc.
Method details
Uploader constructor
public function Uploader(settings:Object)
Constructs a new uploader instance.
Parameters
settings:Object | Initialization settings, to be used by the uploader instance and runtimes. |
bind method
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. |
destroy method
public function destroy():void
Destroys Plupload instance and cleans after itself.
getFile method
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;
init method
public function init():void
Initializes the Uploader instance and adds internal event listeners.
refresh method
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.
removeFile method
public function removeFile(file:File):void
Removes a specific file.
Parameters
file:File | File to remove from queue. |
splice method
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.
start method
public function start():void
Starts uploading the queued files.
stop method
public function stop():void
Stops the upload of the queued files.
trigger method
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. |
unbind method
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. |
unbindAll method
public function unbindAll():void
Removes all event listeners.
Event details
BeforeUpload event
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. |
ChunkUploaded event
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. |
Destroy event
public event Destroy(uploader:Uploader)
Fires when destroy method is called.
Parameters
uploader:Uploader | Uploader instance sending the event. |
Error event
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. |
FilesAdded event
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. |
FilesRemoved event
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. |
FileUploaded event
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. |
Init event
public event Init(uploader:Uploader)
Fires when the current RunTime has been initialized.
Parameters
uploader:Uploader | Uploader instance sending the event. |
PostInit event
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. |
QueueChanged event
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. |
Refresh event
public event Refresh(uploader:Uploader)
Fires when the silverlight/flash or other shim needs to move.
Parameters
uploader:Uploader | Uploader instance sending the event. |
StateChanged event
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. |
UploadComplete event
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. |
UploadFile event
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. |
UploadProgress event
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. |
plupload.File
Namespace | plupload |
Class | File |
File instance.
Public Properties
Property | Defined By |
---|---|
id : String
File id this is a globally unique id for the specific file.
| File |
loaded : Number
Number of bytes uploaded of the files total size.
| File |
name : String
File name for example "myfile.
| File |
percent : Number
Number of percentage uploaded of the file.
| File |
size : Number
File size in bytes.
| File |
status : Number
Status constant matching the plupload states QUEUED, UPLOADING, FAILED, DONE.
| File |
Public Methods
Method | Defined By |
---|---|
File(id:String, name:String, size:Number)
Constructs a new file instance.
| File |
Property details
id property
public id : String
File id this is a globally unique id for the specific file.
loaded property
public loaded : Number
Number of bytes uploaded of the files total size.
name property
public name : String
File name for example "myfile.gif".
percent property
public percent : Number
Number of percentage uploaded of the file.
size property
public size : Number
File size in bytes.
status property
public status : Number
Status constant matching the plupload states QUEUED, UPLOADING, FAILED, DONE.
See Also
Method details
File constructor
public function File(id:String, name:String, size:Number)
Constructs a new file instance.
Parameters
id:String | Unique file id. |
name:String | File name. |
size:Number | File size in bytes. |