Skip to content
A `StreamStack` subclass that parses "multipart" data, often from SMTP or HTTP.
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
example/html-upload
tests
.gitignore
README.md
index.js
package.json Remove unused package.json fields. Nov 7, 2011
parseContentType.js
parser.js
partParser.js

README.md

node-multipart-stack

A StreamStack subclass that parses "multipart" data, often from SMTP or HTTP.

This module implements Section 7.2 of RFC 1341. It can be easily used in conjunction with any node ReadableStream.

Usage

Here's a simple HTTP server that can parse multipart requests, like from an HTML multipart form.

var http = require('http');
var multipart = require('multipart-stack');

var server = http.createServer(function(req, res) {

  // includes a built-in "Content-Type Parser"
  var parsed = multipart.parseContentType(req.headers['content-type']);

  if (parsed.type === 'multipart') {
    var parser = new multipart.Parser(req, parsed.boundary);

    // A 'part' event gets fired once per individual "part" of the multipart body
    parser.on('part', function (part) {
      // the 'part' arg is a `ReadableStream` that also emits a 'headers' event.
      part.on('headers', function(headers) {
        console.log(headers);
      });
      part.pipe(process.stdout, { end: false });
    });
  } else {
    // non-file-upload logic
  }

});
Something went wrong with that request. Please try again.