Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including multipart-stack with all npm packages installed. Try it out:

var multipartStack = require("multipart-stack")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

multipart-stack v0.0.4

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

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) {
  var parsed = multipart.parseContentType(req.headers['content-type']);
  if (parsed.type === 'multipart') {
    var parser = new multipart.Parser(req, parsed.boundary);
    parser.on('part', function(part) {
      // Fired once for each individual part of the multipart message.
      // 'part' is a ReadableStream that also emits a 'headers' event.
      part.on('headers', function(headers) {
        console.log(headers);
      });
      part.pipe(process.stdout);
    });
  }
});
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free