0.2.4 • Published 6 years ago
multipart-data-helper v0.2.4
multipart-data
A minimal helper for you need work with multipart requests.
Installation
npm install --save multipart-data
Import
import MultipartData from "multipart-data-helper";
Usage
const xhr = new XMLHttpRequest();
const multipartData = new MultipartData('multipart/mixed');
const image = 'Da23sdnn3wun43fskm'; //Binary data to string;
const data = { foo: 'bar' };
const imageHeader = new Map();
imageHeader.set('Content-Type', 'image/jpeg');
multipartData.append(image, imageHeader);
const dataHeader = new Map();
dataHeader.set('Content-Disposition', 'form-data')
.set('name', 'foo')
.set('filename', 'foo.json')
.set('Content-Type', 'application/json');
multipartData.append(data, dataHeader);
xhr.setRequestHeader("Content-type", multipartData.contentType);
xhr.send(multipartData.multipartBody);
License
MIT
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Crafted with <3 by José Aleu Núñez (@PepeAleu).
This package was initially generated with yeoman and the p generator.