resumable-js-hapi
v0.1.0
Published
resumable.js backend implementation for hapi
Downloads
3
Readme
Resumable.js Hapi
This is a resumable.js backend for Hapi. It is adapted from this example.
Usage
Register the plugin the usual way. Access the object from server.plugins['resumable-js-hapi'].service
,
or construct your own like so:
var ResumableJsService = require('resumable-js-hapi/lib/resumable-js-service');
var service = new ResumableJsService();
- Check if chunk exists:
server.plugins['resumable-js-hapi'].service.get(request).then(exists => {
if (exists) {
reply();
} else {
reply().code(404);
}
}).catch(err => {
// something went wrong
})
- Accept chunk:
var resumable = server.plugins['resumable-js-hapi'].service;
resumable.post(request).then(result => {
if (result.complete) {
// final chunk uploaded
var stream = getSomeSortOfWritableStream();
resumable.write(result.identifier, stream).then(() => {
// Delete chunks
resumable.clean(result.identifier);
// Done combining all the chunks and writing them to stream
});
} else {
// chunk uploaded. more to go.
}
}).catch(err => {
// something went wrong
})