Coder Social home page Coder Social logo

tus-header-parser's Introduction

tus-header-parser

Build Status

Express middleware that parses Tus headers and sets them on req.tus.

  • Ignores syntactically invalid headers
  • Object keys are header names which have been converted to camelCase

Parsed headers:

Tus-Resumable, Upload-Offset, Upload-Length, Upload-Metadata, Upload-Defer-Length, Upload-Checksum, Upload-Concat

Install

npm install --save tus-header-parser

Requires Node v6+

Usage

See ./test directory for usage examples.

import tusParser from 'tus-header-parser'
// ...
app.use(tusParser())
app.use((req, res, next) => {
  console.log(req.headers)
  // {
  //   'tus-resumable': '1.0.0',
  //   'upload-offset': '1000',
  //   'upload-defer-length': '1',
  //   'upload-length': '1337',
  //   'upload-metadata': 'filename d29ybGRfZG9taW5hdGlvbl9wbGFuLnBkZg==,foo YmFy',
  //   'upload-checksum': 'sha Kq5sNclPz7QV2+lfQIuc6R7oRu0=',
  //   'upload-concat': 'final;/files/a /files/b',
  // }
  console.log(req.tus)
  // {
  //   tusResumable: '1.0.0',
  //   uploadOffset: 1000,
  //   uploadDeferLength: 1,
  //   uploadLength: 1337,
  //   uploadMetadata: {
  //     filename: 'world_domination_plan.pdf',
  //     foo: 'bar',
  //   },
  //   uploadChecksum: {
  //     algorithm: 'sha',
  //     checksum: <Buffer 2a ae 6c 35 c9 4f cf b4 15 db e9 5f 40 8b 9c e9 1e e8 46 ed>,
  //   },
  //   uploadConcat: {
  //     final: true,
  //     urls: ['/files/a', '/files/b'],
  //   },
  // }
})

tus-header-parser's People

Contributors

olalonde avatar

Stargazers

danielsdesk avatar

Watchers

Nathan Lands avatar  avatar James Cloos avatar Roger So avatar Carey Janecka avatar Guns avatar Andrej Guran avatar Torsten Rüter 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.