Upload objects with putAnyObject (Smart Upload)
devThe putAnyObject method is the recommended way to upload data. It automatically decides between a single PUT request and a multipart upload based on the data size.
- ≤ 8MB (default): Performs a single
PUTrequest. - > 8MB: Automatically performs a multipart upload with 4 concurrent part uploads, automatic retries (3 attempts with exponential backoff), and automatic cleanup on failure.
Memory Efficiency Tip: For large files, use Blob or File instead of Uint8Array to enable zero-copy slicing, which prevents loading the entire file into memory.
// Small file — uses single PUT internally
await s3.putAnyObject('small.txt', 'Hello World');
// Large file — automatically uses multipart
const largeBuffer = await fs.readFile('video.mp4'); // 500MB
await s3.putAnyObject('videos/movie.mp4', largeBuffer, 'video/mp4');
// Blob (zero-copy slicing for memory efficiency)
const file = new File([largeArrayBuffer], 'data.bin');
await s3.putAnyObject('uploads/data.bin', file);
// ReadableStream (uploads as data arrives)
const stream = fs.createReadStream('huge-file.dat');
await s3.putAnyObject('backups/data.dat', Readable.toWeb(stream));