Skip to content

bharat-dpd/resumable-js-hapi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Resumable.js Hapi

shippable-badge

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
})

About

Resumable.js backend implementation for Hapi

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%