@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 type
  • getObject({ key, bucket? }) - Download a file as a Buffer
  • getSignedUrl({ key, bucket?, expirityTime? }) - Generate a pre-signed URL
  • deleteObject({ key, bucket? }) - Delete a single object
  • deleteObjects({ keys, bucket? }) - Delete multiple objects
  • deleteObjectByPrefix({ keyOrPrefix, bucket? }) - Delete all objects matching a prefix
  • saveOrReplaceObject({ file, key?, fileId, bucket? }) - Replace existing file
  • cloneBucket({ sourceBucket, targetBucket, fromPrefix?, toPrefix? }) - Copy objects between buckets
  • listBuckets() - List all buckets
  • createBucket({ name }) - Create a new bucket
  • send(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
npm
2026-05-09 16:35:28 +03:00
1
Adomas Poniškaitis
MIT
4.4 KiB
Assets (1)
s3-0.0.5.tgz 4.4 KiB
Versions (5) View all
0.0.7 2026-05-09
0.0.6 2026-05-09
0.0.5 2026-05-09
0.0.4 2026-05-09
0.0.2 2026-04-30