Overview
The S3M class provides several methods for managing multipart uploads to AWS S3.upload()
Main method that orchestrates the entire upload process.Returns
Returns a promise that resolves to an object containing upload information.
Return Object (auto_complete: true)
Unique identifier for the upload.
S3 object key where the file is stored.
File extension extracted from the filename.
Original filename.
Public URL of the uploaded file.
Return Object (auto_complete: false)
Unique identifier for the upload.
S3 object key where the file is stored.
File extension extracted from the filename.
Original filename.
AWS S3 upload ID for the multipart upload.
Array of uploaded parts with ETag and PartNumber.
Example
startUpload()
Initiates a multipart upload and gets the upload ID from AWS S3.Returns
Promise that resolves to an object with upload initialization data.
Return Fields
S3 object key for the file.
AWS S3 multipart upload ID.
Unique identifier for the upload.
Example
Throws
Error- If filename is empty
uploadChunks()
Uploads the file in chunks with concurrent upload management.Parameters
S3 object key for the file.
AWS S3 multipart upload ID.
Callback function to receive progress updates.Signature:
(percent: number) => voidReturns
Promise that resolves to an array of uploaded parts, sorted by PartNumber.Each part object contains:
ETag(string): Entity tag from S3PartNumber(number): Part number (1-indexed)
Example
uploadChunk()
Uploads a single chunk with retry logic.Parameters
S3 object key for the file.
AWS S3 multipart upload ID.
Part number (1-indexed).
Blob containing the chunk data.
Total number of chunks in the upload.
Array tracking progress of all chunks.
Callback function to receive progress updates.
Returns
Promise that resolves to a part object.
Return Fields
Entity tag from S3 response headers.
Part number that was uploaded.
Behavior
- Automatically retries failed uploads up to
chunk_retriestimes - Logs warnings when retrying
- Throws error if all retries are exhausted
completeUpload()
Completes the multipart upload on AWS S3.Parameters
S3 object key for the file.
AWS S3 multipart upload ID.
Array of uploaded parts with ETag and PartNumber.
Returns
Promise that resolves to the public URL of the uploaded file.
Example
getSignUrl()
Gets a pre-signed URL from the backend for uploading a specific part.Parameters
S3 object key for the file.
AWS S3 multipart upload ID.
Part number to get signed URL for (1-indexed).
Returns
Promise that resolves to the pre-signed S3 upload URL.
Example
handleUploadProgress()
Handles progress events from chunk uploads and calculates overall progress.Parameters
Progress event from axios upload.Contains
loaded and total properties.Total number of chunks in the upload.
Index of the current chunk (0-indexed).
Array tracking progress percentage of each chunk.
Callback function to receive overall progress updates.Signature:
(percent: number) => voidReturns
This method returnsvoid and updates the progress array and calls the callback.
Behavior
- Calculates the progress percentage for the current chunk
- Updates the progress array at the chunk’s index
- Calculates overall progress as the average of all chunks
- Calls the
updateProgresscallback with the overall percentage
Helper Function: s3m()
Convenience function that creates an S3M instance and immediately starts the upload.Parameters
File object to upload.
Configuration options (same as S3M constructor).
Returns
Returns the same result as callingnew S3M(file, options).upload().