A lightweight, cross-platform Swift package providing a unified API for cloud storage solutions. Currently supports AWS S3 with full feature parity including uploads, downloads, presigned URLs, and comprehensive bucket operations.
- π Lightweight and performant - Zero external dependencies, optimized for speed
- βοΈ AWS S3 Complete - Full S3 API support with native Swift implementation
- π± Cross-platform - iOS 15+, macOS 12+, Linux, tvOS 15+, watchOS 8+
- π‘οΈ Type-safe Swift API - Comprehensive error handling and data validation
- π§ Easy configuration - Environment variables or programmatic setup
- π Secure authentication - AWS Signature V4, session tokens, custom endpoints
- π Rich metadata support - Custom headers and file metadata
- π Presigned URLs - Secure, time-limited access for GET and PUT operations
- β‘ Async/await ready - Modern Swift concurrency support
- π§ͺ Thoroughly tested - Unit tests and CLI integration testing
- π§ CLI Tool included - Complete command-line interface for testing and automation
- iOS 15.0+
- macOS 12.0+
- tvOS 15.0+
- watchOS 8.0+
- Linux
To test in docker, use the following command from the source root.
docker-compose -f ./docker/docker-compose.yml run testTo run on mac simply
swift testThe package includes a command-line interface for testing all StorageClient APIs.
# Build the CLI
swift build --product storage-cli
# Set environment variables for S3
export STORAGE_PROVIDER=s3
export AWS_ACCESS_KEY_ID=your_access_key
export AWS_SECRET_ACCESS_KEY=your_secret_key
export AWS_REGION=us-west-2
export S3_BUCKET=my-test-bucket
# Test file upload
swift run storage-cli uploadAdd the following dependency to your Package.swift file:
dependencies: [
.package(url: "https://github.com/mirfanbashir/storage-api-lite.git", from: "1.0.0")
],
targets: [
.target(
name: "YourTarget",
dependencies: ["StorageApiLite"]
)
]Or add it through Xcode:
- File β Add Package Dependencies
- Enter the repository URL:
https://github.com/mirfanbashir/storage-api-lite.git
import StorageApiLite
// Configure AWS S3
let awsConfig = AWSS3Configuration(
accessKeyId: "your-access-key",
secretAccessKey: "your-secret-key",
region: "us-east-1",
defaultBucket: "my-bucket"
)
// Create S3 client
let s3Client = try StorageAPILite.createClient(config: .awsS3(awsConfig))
// Or use environment-based configuration
let autoClient = try StorageAPILite.createClient(provider: .awsS3)
// Upload a file
let data = "Hello, World!".data(using: .utf8)!
let result = try await s3Client.upload(
data: data,
key: "hello.txt",
bucket: nil, // Uses default bucket
metadata: ["contentType": "text/plain"]
)
// Download a file
let downloadedData = try await s3Client.download(key: "hello.txt", bucket: nil)
let content = String(data: downloadedData, encoding: .utf8)
// List files
let fileList = try await s3Client.listFiles(
bucket: nil,
prefix: "documents/",
maxResults: 100,
continuationToken: nil
)
// Use convenience methods
try await s3Client.uploadString("Hello, Swift!", key: "greeting.txt")
let greeting = try await s3Client.downloadString(key: "greeting.txt")
// Generate presigned URLs
let downloadURL = try await s3Client.generatePresignedURL(
key: "my-file.txt",
bucket: nil,
operation: .read,
expirationTime: 3600 // 1 hour
)
let uploadURL = try await s3Client.generatePresignedURL(
key: "new-file.txt",
bucket: nil,
operation: .write,
expirationTime: 3600
)
// Delete files
try await s3Client.deleteFile(key: "old-file.txt", bucket: nil)
// Check if file exists
let exists = try await s3Client.fileExists(key: "my-file.txt", bucket: nil)For automatic configuration, set these environment variables:
AWS S3:
AWS_ACCESS_KEY_ID- Your AWS access key IDAWS_SECRET_ACCESS_KEY- Your AWS secret access keyAWS_REGION- AWS region (e.g.,us-east-1,eu-west-1)AWS_DEFAULT_BUCKET(optional) - Default S3 bucket nameAWS_ENDPOINT(optional) - Custom endpoint for S3-compatible servicesAWS_SESSION_TOKEN(optional) - For temporary/federated credentials
upload(data:key:bucket:metadata:)- Upload data to storagedownload(key:bucket:)- Download data from storageuploadString(_:key:bucket:metadata:)- Upload string contentdownloadString(key:bucket:)- Download string contentdeleteFile(key:bucket:)- Delete a filefileExists(key:bucket:)- Check if file existslistFiles(bucket:prefix:maxResults:continuationToken:)- List files with paginationgeneratePresignedURL(key:bucket:operation:expirationTime:)- Generate presigned URLs
createBucket(_:region:)- Create a new bucketdeleteBucket(_:)- Delete an empty bucketlistBuckets()- List all accessible buckets
All operations throw StorageError with specific error types:
.invalidKey- Invalid file key format.invalidBucket- Invalid bucket name.fileNotFound- File doesn't exist.insufficientPermissions- Access denied.networkError- Network connectivity issues.configurationError- Invalid configuration
For detailed API documentation, see the inline documentation in the source code.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the terms specified in the LICENSE file.
Fully Implemented Features:
- β File upload/download operations
- β String upload/download convenience methods
- β File existence checks and deletion
- β Bucket creation, deletion, and listing
- β File listing with pagination support
- β Presigned URL generation (GET and PUT)
- β AWS Signature Version 4 authentication
- β Custom endpoints (S3-compatible services)
- β Session token support for temporary credentials
- β Cross-platform compatibility (iOS, macOS, Linux, tvOS, watchOS)
- β Comprehensive error handling
- β CLI tool for testing and automation
- β Zero external dependencies
Version 1.1.0 - Enhanced S3 Features
- Multipart uploads for large files (>5GB)
- Server-side encryption options
- Object tagging support
- Advanced metadata operations
Version 1.2.0 - Performance & Reliability
- Connection pooling and retry logic
- Request timeout configuration
- Progress callbacks for large transfers
- Bandwidth throttling
Version 2.0.0 - Multi-Cloud Support
- Azure Blob Storage integration
- Google Cloud Storage support
- Unified multi-cloud interface
Additional Providers (Future)
- Cloudflare R2
- Wasabi Cloud Storage (100% S3 API compatible)
- Google Cloud Storage (S3-compatible XML API)
- MinIO and other S3-compatible services
- Local filesystem adapter