Uploader Class
Provides core Upload-functionality.
Also definesHTMLInputElement.prototype.sendFiles
.
The Uploader is a Class, which can be instantiated with a config
-object:
{url: {String}, the default url to send to
params: {Object}, the default params that will be send with the request
options: {Object}, the xhr-options (see http://itsa.io/api/classes/IO.html#method_sendBlob)
maxFileSize: {Number}, the maximum filesize for every single file to be accepted. Note that the server needs to
controll this, however, when set, the uploader is enabled to show a proper warning while
rejecting the io-promise
totalFileSize: {Number} the maximum filesize for all files (cummulated) to be accepted. Note that the server needs to
controll this, however, when set, the uploader is enabled to show a proper warning while
rejecting the io-promise
}
Copyright (c) 2014 ITSA - https://github.com/itsa New BSD License - http://choosealicense.com/licenses/bsd-3-clause/
Item Index
Methods
Properties
Methods
_defFnSelectFiles
-
e
Default function for the uploader:selectfiles
-event
_defFnSend
-
e
Default function for the uploader:send
-event
_storeLastSent
()
private
chainable
Stores the files that are sent into an internal hash, which can be read by getLastSent()
.
clearDefaults
()
chainable
Clears the default transition-values that are being used for the values of url
, paramsand
options`.
count
()
Number
Returns the number of files that are currently selected.
Returns:
Number of files currently selected
destroy
()
Destroys the fileselector: removes all eventlisteners and removes its protected input
-domNode.
getDomNode
()
DOMNode
Returns the protected input
-domNode whichis being used by this uploader-instance.
Returns:
protected input
-domNode
getFiles
()
Array-like
Returns the currently selected files. This is an Array-like
object, not a true Array.
Returns:
protected input
-domNode
getLargestFileSize
()
Number
Returns the size of the largest file that is currently selected.
Returns:
The size of the largest file in bytes
getLastSent
()
Array
Returns the last send-files. This is handy to know, because after transmission, getFiles() will return empty. This is an true Array with objects of this structure: {name: xxx, size: xxx}
Returns:
The last sent files
getTotalFileSize
()
Number
Returns the total size of all files that are currently selected.
Returns:
The size of all files in bytes
hasFiles
()
Number
Whether there are currently files selected.
Returns:
Number of selected files
selectFile
-
[payload]
Pops-up the browser's fileselect, by emitting the 'uploader:selectfiles'-event.
The fileselector allows you to send only 1 file at a time.
If payload.autoSend
is set, the files will automaticly be send after selection.
You also can set other properties at the payload --> these will be available at the listeners.
selectFiles
-
[payload]
Pops-up the browser's fileselect, by emitting the 'uploader:selectfiles'-event.
The fileselector allows you to send multiple files at a time.
If payload.autoSend
is set, the files will automaticly be send after selection.
You also can set other properties at the payload --> these will be available at the listeners.
send
-
[payload]
Send the selected files, by emitting the 'uploader:send'-event.
If payload.url
, payload.url
or payload.url
is set, then these will overrule the default
values (the way they were set at initiation, or by using setDefaults
).
You also can set other properties at the payload --> these will be available at the listeners.
setDefaults
-
[url]
-
[params]
-
[options]
-
[maxFileSize]
-
[totalFileSize]
Sets the default transition-values that are being used for the values of url
, paramsand
options`.
These values might have been set during initialization, if so, any values passed will be overrule the previous.
Parameters:
-
[url]
String optionalthe default url to send to
-
[params]
Object optionalthe default params that will be send with the request
-
[options]
Object optionalthe xhr-options (see http://itsa.io/api/classes/IO.html#method_sendBlob)
-
[maxFileSize]
Number optionalthe maximum filesize for every single file to be accepted. Note that the server needs to controll this, however, when set, the uploader is enabled to show a proper warning while rejecting the io-promise
-
[totalFileSize]
Number optionalthe maximum filesize for all files (cummulated) to be accepted. Note that the server needs to controll this, however, when set, the uploader is enabled to show a proper warning while rejecting the io-promise
Properties
_inputNode
DOMNode
private
Hidden input-node
of the type file
that is being used to transfer the files.
_lastfiles
Array
private
Private Array with objects of this structure: {name: xxx, size: xxx}. Holds the file-info of all files that have been send by the last transfer. Can be used by the method: getLastSent()
Default: []
Events
uploader:fileschanged
Fired internally whenever the selected files are changed.
Its defaultFn will start sending the files (if the selection is triggered with autoSend=true
)
uploader:selectfiles
Fired to start selecting the files. Its defaultFn will pop-up the file-selector.
uploader:send
Fired to start uploading through io.
Its defaultFn will invoke sendFiles
of the input-node.