multipart-payload-transformer
An element to transform FormData
object into Multipart message and ArrayBuffer
.
Usage
Installation
npm install --save @advanced-rest-client/multipart-payload-transformer
In a LitElement
import { LitElement, html } from 'lit-element';
import '@advanced-rest-client/code-mirror/code-mirror.js';
class SampleElement extends PolymerElement {
render() {
const formData = new FormData();
formData.add('filed', new Blob(['test'], { type: 'text/plain' }));
return html`
<multipart-payload-transformer .formData="${formData}"></multipart-payload-transformer>
`;
}
async run() {
const message = await this.shadowRoot.querySelector('multipart-payload-transformer').generateMessage();
console.log(message);
}
}
customElements.define('sample-element', SampleElement);
In a Polymer 3 element
import {PolymerElement, html} from '@polymer/polymer';
import '@advanced-rest-client/multipart-payload-transformer/multipart-payload-transformer.js';
class SampleElement extends PolymerElement {
static get template() {
return html`
<multipart-payload-transformer formdata="[[formData]]"></multipart-payload-transformer>
`;
}
static get properties() {
return {
formData: Object
}
}
constructor() {
super();
const fd = new FormData();
fd.add('test', 'value');
this.formData = fd;
}
}
customElements.define('sample-element', SampleElement);
Development
git clone https://github.com/advanced-rest-client/multipart-payload-transformer
cd multipart-payload-transformer
npm install
Running the demo locally
npm start
Running the tests
npm test
API components
This components is a part of API components ecosystem