Maltypart
Maltypart is a simple multipart request builder.
It is very similar to HTML5 FormData, but offers a bit more control over fields and serialization.
Why Maltypart?
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.
Usage
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 = ;
Appending Strings:
// request is from the first example request;
Appending Typed Content:
request;
Appending a File:
request;
Using with XMLHttpRequest:
// A standard XHRvar xhr = ;xhr; // Set the request's content-type appropriately:xhr; // Set the multipart-encoded body:xhr;
Instantiation
Via node / browserify:
var maltypart = ;
Via AMD / requirejs:
;
Via globals / script tag:
Installation
Installation via Bower: (Recommended)
bower install maltypart
Manual Download:
- maltypart.js - full source with comments, for development
- maltypart.min.js - minified without comments, for production
License
BSD