Skip to content

adrien-thierry/smartupload.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

smartupload.js

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

Format

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

Server

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.

Functionalities

  1. async/sync upload
  2. auto retry when upload fail
  3. choose a size of chunk to send
  4. catch all events to show a progress/status bar

Properties

  • 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 ?

Methods

  1. destruct -- clear the handle event of the file input

Events

  1. errorHandler
  2. abortReadding
  3. onLoadStart
  4. updateProgress
  5. onProgress

About

Smart upload lib in js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published