当前位置: 首页 > 工具软件 > Plupload > 使用案例 >

jquery 文件上传 Plupload API

严子默
2023-12-01

从官网中复制部分API,方便今后查看。

plupload.Uploader

Namespaceplupload
ClassUploader
Uploader class, an instance of this class will be created for each upload field. 

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

MethodDefined 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
QueueChanged(uploader: Uploader)
Fires when the file queue is changed.
Uploader
Refresh(uploader: 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
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

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.

files property

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

See Also

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:ObjectInitialization 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:StringEvent name to listen for.
func:functionFunction to call ones the event gets fired.
scope:ObjectOptional 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:StringFile 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:FileFile 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:StringEvent 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:StringName of event to remove.
func:functionFunction 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:UploaderUploader instance sending the event.
file:FileFile to be uploaded.

ChunkUploaded event

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

Parameters

uploader:UploaderUploader instance sending the event.
file:FileFile that the chunk was uploaded for.
response:ObjectObject with response properties.

Destroy event

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

Parameters

uploader:UploaderUploader instance sending the event.

Error event

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

Parameters

uploader:UploaderUploader instance sending the event.
error:ObjectContains 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:UploaderUploader instance sending the event.
files:ArrayArray 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:UploaderUploader instance sending the event.
files:ArrayArray 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:UploaderUploader instance sending the event.
file:FileFile that was uploaded.
response:ObjectObject with response properties.

Init event

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

Parameters

uploader:UploaderUploader 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:UploaderUploader 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:UploaderUploader instance sending the event.

Refresh event

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

Parameters

uploader:UploaderUploader 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:UploaderUploader instance sending the event.

UploadComplete event

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

Parameters

uploader:UploaderUploader instance sending the event.
files:ArrayArray 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:UploaderUploader instance sending the event.
file:FileFile 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:UploaderUploader instance sending the event.
file:FileFile that is currently being uploaded.


plupload.File

Namespaceplupload
ClassFile
File instance.

Public Properties

PropertyDefined 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

MethodDefined 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:StringUnique file id.
name:StringFile name.
size:NumberFile size in bytes.

 类似资料: