Skip to main content

Crate crypsol_storage

Crate crypsol_storage 

Source
Expand description

§Crypsol Storage

Multi-cloud storage library for Rust with image processing, validation, and thumbnail generation.

§Backends

FeatureBackendPresigned URLs
s3 (default)AWS S3, Cloudflare R2, MinIOYes
gcsGoogle Cloud StorageNo
azureAzure Blob StorageNo
localLocal filesystem (dev/testing)No

§Quick start

use crypsol_storage::{S3Backend, StorageConfig, StorageService, ImageUploadConfig};

let backend = S3Backend::builder()
    .region("us-east-1")
    .bucket("my-bucket")
    .credentials("AKID...", "secret...")
    .build()?;

let service = StorageService::new(backend, StorageConfig::default());

// Upload an image with automatic thumbnail generation
let config = ImageUploadConfig::default();
let result = service
    .upload_image_with_config(&image_bytes, "image/jpeg", &config)
    .await?;

println!("Image:     {}", result.url);
println!("Thumbnail: {}", result.thumbnail_url);

See the README for full examples covering every backend and API method.

Re-exports§

pub use backends::s3::S3Backend;
pub use backends::s3::S3BackendBuilder;
pub use backends::gcs::GcsBackend;
pub use backends::gcs::GcsBackendBuilder;
pub use backends::gcs::GcsCredentials;
pub use backends::azure::AzureBackend;
pub use backends::azure::AzureBackendBuilder;
pub use backends::local::LocalBackend;

Modules§

backends

Structs§

DownloadResult
Result of downloading an object.
FileUploadResult
Result of a generic file upload.
ImageUploadConfig
Configuration for image upload operations.
PresignedUploadResult
Result of a presigned upload URL generation.
PutOptions
Options for object upload.
RawDownloadResult
Raw result from a storage backend get_object call.
StorageConfig
Configuration for the StorageService.
StorageService
High-level storage service that wraps a StorageBackend and adds image processing, validation, atomic uploads, and download limits.
UploadResult
Result of a successful image upload containing both URLs.

Enums§

Error
Custom error type for storage-related failures.

Constants§

ALLOWED_IMAGE_TYPES
Allowed image MIME types for upload validation.
MAX_PRESIGN_EXPIRY_SECS
Maximum presigned URL expiry in seconds (7 days).
PROFILE_IMAGE_SIZE
Profile image dimensions (full size).
THUMBNAIL_SIZE
Profile thumbnail dimensions.

Traits§

StorageBackend
Trait for storage backends.

Functions§

generate_storage_key
Generates a unique storage key. Format: {folder}/{YYYY/MM/DD}/{uuid}.{extension}
generate_thumbnail_key
Generates the thumbnail key from the main image key.
validate_content_type
Validates the content type against allowed image types.
validate_expiry
Validates presigned URL expiry is within the 7-day limit.
validate_file_size
Validates the file size against the provided maximum.