package
Isomorphic TypeScript file upload library.
npm install uploadGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Isomorphic TypeScript file upload library for browser and node.js environments.
Quickstart:
npm install upload
# ...or
yarn add uploadimport { upload } from 'upload';
async function test() {
const response = await upload(
'https://example.com/upload',
{
file: someInput.file,
},
{
onProgress: progress => (element.innerText = progress * 100 + '%'),
}
);
console.log(response);
}async function test() {
const upload = new Upload({
url: 'https://example.com/upload',
form: {
file: someInput.file,
},
headers: {
Authorization: 'Bearer TOKEN',
},
});
upload.on('progress', progress => {
element.innerText = progress * 100 + '%';
});
const response = await upload.upload();
console.log(response);
alert('Done!');
const upload = new Upload({
url: 'https://httpbin.org/post',
form: someInput.file,
});
upload.on('state', () => {
if (upload.state === 'aborted') doSomething();
});
upload.upload();
upload.abort();You can attach event listeners to an instance of Upload with .on:
upload.on('state', state => {
console.log(state);
});Emitted when upload state is changed. Possible states: new, started, aborted, failed, successful.
Emitted when an error occurs.
Emitted when upload progress changes. Progress is a float between 0 and 1.
interface UploadResponse {
data?: string | ArrayBuffer | Blob;
headers?: Record<string, string | string[] | undefined>;
}
interface UploadOptions {
form: Record<string, string | Blob> | FormData | FormDataNode;
url: string;
headers?: Record<string, string>;
}
type UploadState = 'new'
mat-sz
contact@matsz.dev
Estimated unpacked size across 13 packages.
510.9 kB
Includes dependencies.