0.2.4 • Published 6 years ago

multipart-data-helper v0.2.4

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

multipart-data Build Status js-standard-style

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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Crafted with <3 by José Aleu Núñez (@PepeAleu).


This package was initially generated with yeoman and the p generator.

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.1.0

6 years ago