s3

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	urlhandler.Handler
	// contains filtered or unexported fields
}

Client provides S3-compatible object storage operations with URL handling capabilities. It uses the MinIO client library to interact with S3 or S3-compatible services.

func NewClient

func NewClient(conf Config) (*Client, error)

NewClient creates a new S3-compatible storage client with the provided configuration. It automatically configures the public base URL if not provided and initializes the URL handler for public file access.

func (*Client) CopyFile

func (s *Client) CopyFile(ctx context.Context, sourceKey string, destinationKey string, overwrite bool) error

CopyFile duplicates a file from source to destination key within the S3 bucket.

func (*Client) DeleteFile

func (s *Client) DeleteFile(ctx context.Context, key string) error

DeleteFile removes a file from the S3-compatible storage bucket.

func (*Client) DownloadFile

func (s *Client) DownloadFile(ctx context.Context, key string) (storage.DownloadResult, error)

DownloadFile retrieves a file from S3-compatible storage. Returns the file reader, content type, and content size.

func (*Client) GenerateUploadAuth added in v0.0.3

func (s *Client) GenerateUploadAuth(ctx context.Context, req storage.UploadAuthRequest) (storage.UploadAuthResult, error)

GenerateUploadAuth creates a presigned PUT URL for direct client uploads to S3. It generates the storage key using configured naming strategy and returns the presigned URL, storage key, and public access URL. The presigned URL expires after 1 hour.

func (*Client) IsFileExists

func (s *Client) IsFileExists(ctx context.Context, key string) (bool, error)

IsFileExists checks whether a file exists in the S3-compatible storage bucket.

func (*Client) MoveFile

func (s *Client) MoveFile(ctx context.Context, sourceKey string, destinationKey string, overwrite bool) error

MoveFile relocates a file from source to destination key within the S3 bucket. It performs a copy operation followed by deletion of the source file.

func (*Client) UploadFile

func (s *Client) UploadFile(ctx context.Context, file io.Reader, key string) (string, error)

UploadFile uploads data from a reader to S3-compatible storage with the specified key.

func (*Client) UploadLocalFile

func (s *Client) UploadLocalFile(ctx context.Context, file string, key string) (string, error)

UploadLocalFile uploads an existing local file to S3-compatible storage with the specified key.

type Config

type Config struct {
	Endpoint        string                       `json:"endpoint"`
	AccessKeyID     string                       `json:"access_key"`
	SecretAccessKey string                       `json:"secret"`
	Token           string                       `json:"token"`
	Bucket          string                       `json:"bucket"`
	UseSSL          bool                         `json:"use_ssl"`
	PublicBase      string                       `json:"public_base"`
	Dir             string                       `json:"dir" yaml:"dir"`
	UploadNaming    storage.UploadNamingStrategy `json:"upload_naming" yaml:"upload_naming"`
}

Config holds the configuration parameters for S3-compatible object storage.

Jump to

Keyboard shortcuts

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