s3

package
v0.0.2-beta.2 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: MIT Imports: 11 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(config *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) (io.ReadCloser, string, int64, error)

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

func (*Client) GenerateUploadToken

func (s *Client) GenerateUploadToken(ctx context.Context, fileName string, dir string, nameBuilder func(filename string, dir ...string) string) ([3]string, error)

GenerateUploadToken creates a presigned PUT URL for direct client uploads to S3. It generates a unique key based on the filename hash 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"`
}

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