@codingducksrl/multipart-upload
v0.1.4
Published
Small library to handle multipart uploads to AWS S3 buckets.
Readme
multipart-upload
Small library to handle multipart uploads to AWS S3 buckets.
Installation
npm install @codingducksrl/multipart-uploadUsage
import {MultipartUpload} from '@codingducksrl/multipart-upload'
const uploader = new MultipartUpload(
async (id, maxPartSize, fileSize, metadata) => {
// Make the request to the backend to initiate the multipart upload
// It should return an object with uploadId and presignedUrls for each part
return {
upload_id: 'unique-upload-id', // Upload ID generated by S3
parts: [
{
part_number: 1, // Part number
url: 'https://...', // Presigned URL for part 1
start: 0, // Start byte
end: maxPartSize - 1 // End byte
}
]
}
},
async (id, uploadId, parts, checksum, metadata) => {
// Make the request to the backend to complete the multipart upload
},
{} // Options
)
const file = /* get your File or Blob object */
await uploader.upload('unique-id', file)Options
The MultipartUpload class accepts an options object with the following properties:
| Name | Description | Default Value |
|-------------------|---------------------------------------------------|-----------------------------------------------------------|
| maxFilePartSize | Maximum size of each part in bytes | 100 * 1024 * 1024 (100MiB) |
| algorithm | Hashing algorithm to use | 'SHA-256' |
| retryOptions | axios-retry options for retrying failed uploads | { retries: 3, retryDelay: axiosRetry.exponentialDelay } |
