storage

package
v0.9.31 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EstimateThumbnailSize

func EstimateThumbnailSize(origWidth, origHeight int, config ThumbnailConfig) int

EstimateThumbnailSize estimates the size of a thumbnail in bytes This is useful for checking if it will fit within Milvus VARCHAR limits (65KB)

func GenerateSafeThumbnail

func GenerateSafeThumbnail(imageData []byte) (string, error)

GenerateSafeThumbnail generates a thumbnail that fits within Milvus VARCHAR limits Returns base64-encoded thumbnail that is guaranteed to be <65KB

func GenerateThumbnail

func GenerateThumbnail(imageData []byte, config ThumbnailConfig) ([]byte, int, int, error)

GenerateThumbnail creates a thumbnail from an image Returns the thumbnail as bytes and its dimensions

func GenerateThumbnailBase64

func GenerateThumbnailBase64(imageData []byte, config ThumbnailConfig) (string, int, int, error)

GenerateThumbnailBase64 creates a base64-encoded thumbnail

func IsThumbnailNeeded

func IsThumbnailNeeded(imageData []byte) bool

IsThumbnailNeeded checks if a thumbnail is needed to fit within Milvus limits Milvus VARCHAR limit: 65,535 bytes Base64 overhead: 1.37x Safe limit for original image: ~47KB (~48,000 bytes)

Types

type Config

type Config struct {
	// Type of storage (s3, minio, local)
	Type StorageType

	// S3/MinIO configuration
	Endpoint        string // MinIO endpoint (e.g., "localhost:9000")
	AccessKey       string
	SecretKey       string
	Region          string
	Bucket          string
	UseSSL          bool
	PathPrefix      string // Optional prefix for all keys (e.g., "images/")
	PresignDuration time.Duration

	// Local storage configuration (for testing)
	LocalPath string // Base directory for local storage
}

Config contains configuration for storage backends

type ErrDeleteFailed

type ErrDeleteFailed struct {
	URL string
	Err error
}

ErrDeleteFailed is returned when image deletion fails

func (*ErrDeleteFailed) Error

func (e *ErrDeleteFailed) Error() string

func (*ErrDeleteFailed) Unwrap

func (e *ErrDeleteFailed) Unwrap() error

type ErrDownloadFailed

type ErrDownloadFailed struct {
	URL string
	Err error
}

ErrDownloadFailed is returned when image download fails

func (*ErrDownloadFailed) Error

func (e *ErrDownloadFailed) Error() string

func (*ErrDownloadFailed) Unwrap

func (e *ErrDownloadFailed) Unwrap() error

type ErrImageNotFound

type ErrImageNotFound struct {
	URL string
}

ErrImageNotFound is returned when an image doesn't exist

func (*ErrImageNotFound) Error

func (e *ErrImageNotFound) Error() string

type ErrUnsupportedStorageType

type ErrUnsupportedStorageType struct {
	Type string
}

ErrUnsupportedStorageType is returned when an unsupported storage type is requested

func (*ErrUnsupportedStorageType) Error

func (e *ErrUnsupportedStorageType) Error() string

type ErrUploadFailed

type ErrUploadFailed struct {
	URL string
	Err error
}

ErrUploadFailed is returned when image upload fails

func (*ErrUploadFailed) Error

func (e *ErrUploadFailed) Error() string

func (*ErrUploadFailed) Unwrap

func (e *ErrUploadFailed) Unwrap() error

type ImageMetadata

type ImageMetadata struct {
	// Original filename
	Filename string

	// MIME type (e.g., "image/jpeg", "image/png")
	ContentType string

	// Size in bytes
	Size int64

	// Image dimensions
	Width  int
	Height int

	// Collection and document IDs for organization
	CollectionName string
	DocumentID     string

	// Additional custom metadata
	Custom map[string]string
}

ImageMetadata contains metadata about an uploaded image

type ImageStorage

type ImageStorage interface {
	// Upload stores an image and returns its URL
	// The URL format depends on the storage backend:
	// - S3: https://bucket.s3.region.amazonaws.com/path/to/image.jpg
	// - MinIO: http://localhost:9000/bucket/path/to/image.jpg
	Upload(ctx context.Context, image []byte, metadata ImageMetadata) (string, error)

	// Download retrieves an image by its URL
	Download(ctx context.Context, url string) ([]byte, error)

	// Delete removes an image by its URL
	Delete(ctx context.Context, url string) error

	// Exists checks if an image exists at the given URL
	Exists(ctx context.Context, url string) (bool, error)

	// GetURL returns a pre-signed URL for temporary access (if supported)
	// Duration specifies how long the URL should be valid
	// Returns the original URL if pre-signing is not supported
	GetPresignedURL(ctx context.Context, url string, duration time.Duration) (string, error)

	// GetInfo returns metadata about a stored image
	GetInfo(ctx context.Context, url string) (*ImageMetadata, error)
}

ImageStorage defines the interface for external image storage backends

func NewImageStorage

func NewImageStorage(config Config) (ImageStorage, error)

NewImageStorage creates a new ImageStorage instance based on the config

type LocalStorage

type LocalStorage struct {
	// contains filtered or unexported fields
}

LocalStorage implements ImageStorage using local filesystem NOTE: For testing only, not recommended for production

func NewLocalStorage

func NewLocalStorage(config Config) (*LocalStorage, error)

NewLocalStorage creates a new local filesystem storage backend

func (*LocalStorage) Delete

func (s *LocalStorage) Delete(ctx context.Context, imageURL string) error

Delete removes an image by its file path

func (*LocalStorage) Download

func (s *LocalStorage) Download(ctx context.Context, imageURL string) ([]byte, error)

Download retrieves an image by its file path

func (*LocalStorage) Exists

func (s *LocalStorage) Exists(ctx context.Context, imageURL string) (bool, error)

Exists checks if an image exists at the given path

func (*LocalStorage) GetInfo

func (s *LocalStorage) GetInfo(ctx context.Context, imageURL string) (*ImageMetadata, error)

GetInfo returns metadata about a stored image

func (*LocalStorage) GetPresignedURL

func (s *LocalStorage) GetPresignedURL(ctx context.Context, imageURL string, duration time.Duration) (string, error)

GetPresignedURL returns the original file:// URL (no presigning for local files)

func (*LocalStorage) Upload

func (s *LocalStorage) Upload(ctx context.Context, image []byte, metadata ImageMetadata) (string, error)

Upload stores an image and returns its file path

type MinioStorage

type MinioStorage struct {
	// contains filtered or unexported fields
}

MinioStorage implements ImageStorage using MinIO (S3-compatible)

func NewMinioStorage

func NewMinioStorage(config Config) (*MinioStorage, error)

NewMinioStorage creates a new MinIO storage backend

func NewS3Storage

func NewS3Storage(config Config) (*MinioStorage, error)

NewS3Storage creates a new AWS S3 storage backend Uses the same implementation as MinIO (S3-compatible)

func (*MinioStorage) Delete

func (s *MinioStorage) Delete(ctx context.Context, imageURL string) error

Delete removes an image by its URL

func (*MinioStorage) Download

func (s *MinioStorage) Download(ctx context.Context, imageURL string) ([]byte, error)

Download retrieves an image by its URL

func (*MinioStorage) Exists

func (s *MinioStorage) Exists(ctx context.Context, imageURL string) (bool, error)

Exists checks if an image exists at the given URL

func (*MinioStorage) GetInfo

func (s *MinioStorage) GetInfo(ctx context.Context, imageURL string) (*ImageMetadata, error)

GetInfo returns metadata about a stored image

func (*MinioStorage) GetPresignedURL

func (s *MinioStorage) GetPresignedURL(ctx context.Context, imageURL string, duration time.Duration) (string, error)

GetPresignedURL returns a pre-signed URL for temporary access

func (*MinioStorage) Upload

func (s *MinioStorage) Upload(ctx context.Context, image []byte, metadata ImageMetadata) (string, error)

Upload stores an image and returns its URL

type StorageType

type StorageType string

StorageType represents the type of storage backend

const (
	StorageTypeS3    StorageType = "s3"
	StorageTypeMinio StorageType = "minio"
	StorageTypeLocal StorageType = "local" // For testing only
)

type ThumbnailConfig

type ThumbnailConfig struct {
	// Maximum width in pixels (default: 256)
	MaxWidth int

	// Maximum height in pixels (default: 256)
	MaxHeight int

	// JPEG quality (1-100, default: 85)
	Quality int

	// Output format: "jpeg" or "png" (default: "jpeg")
	Format string
}

ThumbnailConfig contains configuration for thumbnail generation

func DefaultThumbnailConfig

func DefaultThumbnailConfig() ThumbnailConfig

DefaultThumbnailConfig returns sensible defaults for thumbnail generation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL