@ponado/s3 (0.0.5)
Published 2026-05-09 16:35:28 +03:00 by adomas
Installation
@ponado:registry=npm install @ponado/s3@0.0.5"@ponado/s3": "0.0.5"About this package
@ponado/s3
AWS S3 wrapper with common operations and automatic file type detection.
Installation
pnpm add @ponado/s3
Usage
import { createS3Client } from '@ponado/s3';
const s3 = createS3Client({
region: 'us-east-1',
endpoint: 'https://s3.amazonaws.com',
defaultBucket: 'my-bucket',
credentials: {
accessKeyId: 'your-access-key',
secretAccessKey: 'your-secret-key'
},
forcePathStyle: false
});
// Upload a file
const result = await s3.uploadObject({
file: buffer,
fileId: 'unique-id'
});
// Get a signed URL
const { signedUrl } = await s3.getSignedUrl({ key: 'path/to/file' });
// Download a file
const { objectBuffer } = await s3.getObject({ key: 'path/to/file' });
// Delete files
await s3.deleteObject({ key: 'path/to/file' });
await s3.deleteObjects({ keys: ['file1', 'file2'] });
await s3.deleteObjectByPrefix({ keyOrPrefix: 'folder/' });
Features
- Automatic file type detection from buffer content
- Signed URL generation
- Batch operations (delete multiple objects)
- Bucket cloning between buckets
- Works with S3-compatible services (MinIO, etc.)
API
createS3Client(config)
Creates an S3 client instance with the following methods:
uploadObject({ file, fileId, bucket? })- Upload a file with auto-detected typegetObject({ key, bucket? })- Download a file as a BuffergetSignedUrl({ key, bucket?, expirityTime? })- Generate a pre-signed URLdeleteObject({ key, bucket? })- Delete a single objectdeleteObjects({ keys, bucket? })- Delete multiple objectsdeleteObjectByPrefix({ keyOrPrefix, bucket? })- Delete all objects matching a prefixsaveOrReplaceObject({ file, key?, fileId, bucket? })- Replace existing filecloneBucket({ sourceBucket, targetBucket, fromPrefix?, toPrefix? })- Copy objects between bucketslistBuckets()- List all bucketscreateBucket({ name })- Create a new bucketsend(command)- Send raw AWS SDK commands
Dependencies
Dependencies
| ID | Version |
|---|---|
| @aws-sdk/client-s3 | ^3.1045.0 |
| @aws-sdk/s3-request-presigner | ^3.1045.0 |
| file-type | ^22.0.1 |
Development dependencies
| ID | Version |
|---|---|
| @types/node | ^20.19.40 |
| bumpp | ^11.1.0 |
| tsdown | ^0.21.10 |
| typescript | ^6.0.3 |
| vitest | ^1.6.1 |
Details
Assets (1)
Versions (5)
View all
s3-0.0.5.tgz
4.4 KiB