Upload lib in js, simple and smart :
var smartUp = new SmartUpload("inputFileId", "http://target/upload.php");
The SmartUpload object handle the file input selection, and send chunk of file to the server.
You can add events/cb easily :
smartUp.updateProgress = function(){ /* DO SOMETHING HERE */ };
Or change chunks size, method and send data synchronously:
smartUp.smartSize = 1024 * 100; //100 Ko DEFAULT => 128Ko
smartUp.smartMethod = "PUT"; // DEFAULT => "POST"
smartUp.smartAsync = true; // DEFAULT => false
smartUp.smartTimeout = 5000; // DEFAULT => 1000 in ms
Chunks of data are sent with POST method, with multipart/form-data enctype. the result is a POST Object :
- data -- the chunk of data in binary format
- id -- the id of the file (== filename)
- type -- the mimeType of the file
- chunkIndex -- the chunk index, begin at 0
- chunkLength -- the length of chunk sent
- chunkStart -- the start of chunk sent in the file
- chunkTotal -- the length of the file
The server must return a JSON object with at least this field :
{
code:0
}
If code != 0, an error occured and smartupload.js will try to reupload the chunk after the smartTimeout delay.
- async/sync upload
- auto retry when upload fail
- choose a size of chunk to send
- catch all events to show a progress/status bar
- smartSize -- INT -- the size of each chunk, in octet
- smartTimeout -- INT -- the timeout before re-send data when error occured in ms
- smartAsync -- BOOL - Is data are sent synchronously or not ?
- destruct -- clear the handle event of the file input
- errorHandler
- abortReadding
- onLoadStart
- updateProgress
- onProgress