Skip to main content

Overview

The S3M class is the core JavaScript class that handles multipart file uploads to AWS S3. It manages chunking, concurrent uploads, retry logic, and progress tracking.

Constructor

const uploader = new S3M(file, options);
file
File
required
The File object to upload. This is a standard browser File object.
options
Object
Configuration options for the upload. See the Options page for details.

Class Constants

The S3M class defines several default constants that control upload behavior:
DEFAULT_CHUNK_SIZE
number
default:"10485760"
Default chunk size in bytes (10MB). This is the size of each part in the multipart upload.
S3M.DEFAULT_CHUNK_SIZE // 10 * 1024 * 1024 = 10MB
DEFAULT_MAX_CONCURRENT_UPLOADS
number
default:"5"
Maximum number of chunks that can be uploaded concurrently.
S3M.DEFAULT_MAX_CONCURRENT_UPLOADS // 5
DEFAULT_MAX_CHUNK_RETRIES
number
default:"3"
Maximum number of retry attempts for a failed chunk upload.
S3M.DEFAULT_MAX_CHUNK_RETRIES // 3

Instance Properties

After instantiation, the S3M instance has the following properties:
file
File
The File object being uploaded.
options
Object
The options object passed to the constructor.
chunkSize
number
The chunk size for the upload. Defaults to DEFAULT_CHUNK_SIZE if not specified in options.
maxConcurrentUploads
number
Maximum number of concurrent chunk uploads. Defaults to DEFAULT_MAX_CONCURRENT_UPLOADS if not specified.
fileName
string
The name of the file being uploaded (from file.name).
fileSize
number
The size of the file in bytes (from file.size).
fileType
string
The MIME type of the file (from file.type).
httpClient
Object
The HTTP client used for requests. Defaults to axios if not provided in options.
chunkRetries
number
Maximum number of retries for failed chunks. Defaults to DEFAULT_MAX_CHUNK_RETRIES if not specified.

Example Usage

import S3M from '@savannabits/s3m';

// Create an instance
const file = document.getElementById('file-input').files[0];
const uploader = new S3M(file, {
  chunk_size: 5 * 1024 * 1024, // 5MB chunks
  max_concurrent_uploads: 3,
  progress: (percent) => {
    console.log(`Upload progress: ${percent}%`);
  }
});

// Start the upload
const result = await uploader.upload();
console.log('Upload complete:', result);

Build docs developers (and LLMs) love