Giter Site home page Giter Site logo

ruploads's Introduction

ruploads

About ruploads

ruploads middleware adds support for resumable uploads via Content-Range and Range headers using HTTP statuscode 308. ruploads comes with an IOS client, browser client utilizing HTML5 File api, the node.js client extends superagent with resume capabilities and ads support for streamed uploads for extremely large files.

When an upload completes, either via the first request or later resume the results are delivered to the next middleware in chain in the same req.files format express.js uses through formidable.

HTTP Flow - asking upload status, target identified by ETag:

PUT /uploads HTTP/1.1
Host: localhost:3000
Content-Length: 0
Content-Range: bytes */123445678
ETag: "abcdefg"

HTTP Flow - the server responds with the range it already has for "abcdefg":

HTTP/1.1 308 Resume Incomplete
Content-Length: 0
Range: 0-12345664
ETag: "abcdefg"

Usage

Basic middleware usage, for options see code comments.

var express = require('express')
  , ruploads = require('ruploads');

var app = express();
var uploads = ruploads({});
/*
  use uploads.set('')
*/
app.use(express.basicAuth('user','pass'));
app.all('/uploads', uploads, function(req, res, next) {
    console.log("upload complete", req.files);
});

Upload and resume HTTP request flow

Client initializez a new resumable upload by issuing A PUT to the upload path:

PUT /upload HTTP/1.1
Host: localhost:3000
Content-Type: application/octet-stream
Content-Disposition: form-data; name="myfile"; filename="ad.gif"
Content-Length: 123445678
ETag: "etag identifying the file, like md5 or other identifier."

If the upload is interupted, the client can ask for the upload state:

PUT /upload HTTP/1.1
Host: localhost:3000
Content-Type: application/octet-stream
Content-Disposition: form-data; name="myfile"; filename="ad.gif"
Content-Length: 0
Content-Range: bytes */123445678
ETag: "etag identifying the file, like md5 or other identifier."

And server responds with what byte range it did already receive:

HTTP/1.1 308 Resume Incomplete
Content-Length: 0
Range: bytes=0-12345664

And the client resumes the upload from bytes 12345664:

PUT /uploads HTTP/1.1
Host: localhost:3000
Content-Length: 111100014
Content-Type: application/octet-stream
Content-Range: bytes 12345665-123445677/123445678
ETag: "etag identifying the file, like md5 or other identifier."

<bytes 12345665-123445677>

ruploads's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.