Maltypart is a simple multipart request builder.
It is very similar to HTML5 FormData, but offers a bit more control over fields and serialization.
Maltypart is a good fit if your app needs to work with multipart form submissions, but you don't want to couple networking logic to your HTML. It supports a few nice additions that FormData doesn't offer, and can serialize Strings, Files, Elements and more.
Creating a new RequestBody:
// Pull in the dependency however you wish: AMD, CJS, Node and globals are all supportedvar RequestBody = RequestBody;// Create a new multipart body:var request = ;
// request is from the first examplerequest;
Appending Typed Content:
Appending a File:
Using with XMLHttpRequest:
// A standard XHRvar xhr = ;xhr;// Set the request's content-type appropriately:xhr;// Set the multipart-encoded body:xhr;
Via node / browserify:
var maltypart = ;
Via AMD / requirejs:
Via globals / script tag:
Installation via Bower: (Recommended)
bower install maltypart
- maltypart.js - full source with comments, for development
- maltypart.min.js - minified without comments, for production