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.
View Demo
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:
var RequestBody = require('maltypart').RequestBody;
var request = new RequestBody();
Appending Strings:
request.append({
some_key : "some value",
second_key : "second value"
});
Appending Typed Content:
request.append('example_image', {
contentType : "image/png",
data : "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD"
+ "///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDe"
+ "NGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC"
});
Appending a File:
request.append('some_file', new File(), function() {
});
Using with XMLHttpRequest:
var xhr = new XMLHttpRequest();
xhr.open('POST', '/upload', true);
xhr.setRequestHeader('Content-Type', request.getContentType());
xhr.send( request.getData() );
Instantiation
Via node / browserify:
var maltypart = require('maltypart');
Via AMD / requirejs:
define(['maltypart'], function(maltypart) {
});
Via globals / script tag:
<script src="maltypart.js"></script>
<script>
maltypart;
</script>
Installation
Installation via Bower: (Recommended)
bower install maltypart
Manual Download:
License
BSD