file upload and progress api
$ component install component/upload
erroran error occurredabortupload was abortedprogress(e) upload in progress (e.percent,e.totalSizeetc)endupload is complete
Initialize an Upload with the given file, where file
is a File object, for example from a input.files[0] FileList.
var upload = new Upload(file);
var upload = Upload(file);POST the multipart upload to path and invoke fn(err, res).
upload.to('/upload');
upload.on('progress', reportProgress);
upload.on('end', done);Creates the xhr for the given path. Calling setPath will setup the following:
upload.req- xhr objectupload.body- FormData
Use a parameter name other than file for your file.
Start the upload.
If the defaults are not correct for you use case, you can modify your upload before starting: In this example we have to include some extra information with our upload:
- the parameter name for the file is
audioinstead offile upload.req(the xhr) is accessed to set an Authorization headerupload.body(the FormData) is accessed to append an additional form field
var upload = new Upload(file);
upload.setPath('https://uploads.example.com/');
upload.setParamName('audio');
upload.req.setRequestHeader('Authorization', myAuth);
upload.body.append('templateId', 'some-uuid');
upload.start(function() {
console.log('hooray!');
});Run the Express test server:
$ npm install
$ make test
MIT