files

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 14 Imported by: 0

README

Go Files SDK

A unified storage SDK for Go services that need one client shape across object and blob storage providers. Heavily inspired by files-sdk by Hayden Bleasel

Highlights

  • One API across providers: call Upload, Download, Head, Exists, Delete, Copy, Move, List, ListAll, Search, URL, and SignedUploadURL against any adapter.
  • Go-native bodies: upload strings, byte slices, readers, files, or custom read closers with the files.Body helpers.
  • File handles: bind repeated operations to one key with client.File("backups/backup.sql").
  • Operational controls: configure prefixes, read-only clients, timeouts, retries, hooks, middleware, progress, bulk work, and transfers.
  • Provider escape hatch: use client.Raw() when provider-specific behavior belongs in the native client.

Install

go get github.com/cersho/gofiles-sdk

Requires Go 1.26 or newer.

Quick Start

package main

import (
	"context"
	"fmt"

	files "github.com/cersho/gofiles-sdk"
	"github.com/cersho/gofiles-sdk/providers/memory"
)

func main() {
	ctx := context.Background()
	client := files.MustNew(files.Options{Adapter: memory.New(memory.Options{})})

	if _, err := client.Upload(ctx, "reports/q1.txt", files.StringBody("revenue: 42"), files.UploadOptions{ContentType: "text/plain"}); err != nil {
		panic(err)
	}

	stored, err := client.Download(ctx, "reports/q1.txt", files.DownloadOptions{})
	if err != nil {
		panic(err)
	}

	text, err := stored.Text(ctx)
	if err != nil {
		panic(err)
	}

	fmt.Println(text)
	// Output: revenue: 42
}

Save it as main.go, run go run ., then swap the memory adapter for a cloud provider when you are ready.

Provider Packages

Import only the adapter you use:

Backend Import path
Memory github.com/cersho/gofiles-sdk/providers/memory
Filesystem github.com/cersho/gofiles-sdk/providers/fs
S3 github.com/cersho/gofiles-sdk/providers/s3
Cloudflare R2 github.com/cersho/gofiles-sdk/providers/r2
S3-compatible storage github.com/cersho/gofiles-sdk/providers/s3compatible
Appwrite github.com/cersho/gofiles-sdk/providers/appwrite
DigitalOcean Spaces github.com/cersho/gofiles-sdk/providers/digitaloceanspaces
Supabase Storage github.com/cersho/gofiles-sdk/providers/supabase
UploadThing github.com/cersho/gofiles-sdk/providers/uploadthing
Vercel Blob github.com/cersho/gofiles-sdk/providers/vercelblob

S3-backed adapters use AWS SDK for Go v2, which is already declared by the module.

Development

Run these commands from the repository root:

bun install
bun run test
bun run build
bun run docs:dev

License

MIT

Documentation

Index

Constants

View Source
const DefaultResumablePartSize int64 = 5 * 1024 * 1024
View Source
const DefaultURLExpiresIn = time.Hour

Variables

View Source
var ProviderNames = []string{"appwrite", "digitalocean-spaces", "fs", "memory", "r2", "s3", "s3-compatible", "supabase", "uploadthing", "vercel-blob"}
View Source
var Providers = map[string]Provider{
	"appwrite": {
		Slug:        "appwrite",
		Name:        "Appwrite",
		Description: "Appwrite Storage via the Storage REST API.",
		Env: ProviderEnvSpec{
			Config: []string{"bucket", "endpoint", "projectId"},
			Required: []EnvVar{
				{Key: "APPWRITE_PROJECT_ID", Aliases: []string{"NEXT_PUBLIC_APPWRITE_PROJECT_ID"}, Description: "Appwrite project ID", Secret: false, ReadBy: "gofiles-sdk"},
			},
			CredentialModes: []EnvGroup{{
				Label: "API key",
				Vars: []EnvVar{
					{Key: "APPWRITE_API_KEY", Aliases: []string{"APPWRITE_KEY"}, Description: "Appwrite API key", Secret: true, ReadBy: "gofiles-sdk"},
				},
			}},
			Optional: []EnvVar{
				{Key: "APPWRITE_ENDPOINT", Aliases: []string{"NEXT_PUBLIC_APPWRITE_ENDPOINT"}, Description: "Appwrite API endpoint", Secret: false, ReadBy: "gofiles-sdk"},
			},
			Notes: "File IDs must be Appwrite-compatible IDs: max 36 characters, no slashes.",
		},
	},
	"digitalocean-spaces": {
		Slug:        "digitalocean-spaces",
		Name:        "DigitalOcean Spaces",
		Description: "DigitalOcean Spaces via the S3-compatible API.",
		Env: ProviderEnvSpec{
			Config: []string{"bucket", "region"},
			CredentialModes: []EnvGroup{{
				Label: "Access key",
				Vars: []EnvVar{
					{Key: "DO_SPACES_KEY", Description: "Spaces access key", Secret: true, ReadBy: "gofiles-sdk"},
					{Key: "DO_SPACES_SECRET", Description: "Spaces secret key", Secret: true, ReadBy: "gofiles-sdk"},
				},
			}},
		},
		PeerDeps: []string{"github.com/aws/aws-sdk-go-v2/service/s3"},
	},
	"fs": {
		Slug:        "fs",
		Name:        "Filesystem",
		Description: "Local filesystem storage for development, tests, and single-node deployments.",
		Env: ProviderEnvSpec{
			Config: []string{"root"},
			Notes:  "Stores metadata in sidecar JSON files beside objects.",
		},
	},
	"memory": {
		Slug:        "memory",
		Name:        "Memory",
		Description: "In-memory storage for tests and ephemeral workloads.",
		Env: ProviderEnvSpec{
			Notes: "No environment variables are required. Data is process-local and is lost when the process exits.",
		},
	},
	"r2": {
		Slug:        "r2",
		Name:        "Cloudflare R2",
		Description: "Cloudflare R2 via the S3-compatible HTTP API.",
		Env: ProviderEnvSpec{
			Config: []string{"bucket"},
			Required: []EnvVar{
				{Key: "R2_ACCOUNT_ID", Description: "Cloudflare account ID", Secret: false, ReadBy: "gofiles-sdk"},
			},
			CredentialModes: []EnvGroup{{
				Label: "Access key",
				Vars: []EnvVar{
					{Key: "R2_ACCESS_KEY_ID", Description: "R2 access key ID", Secret: true, ReadBy: "gofiles-sdk"},
					{Key: "R2_SECRET_ACCESS_KEY", Description: "R2 secret access key", Secret: true, ReadBy: "gofiles-sdk"},
				},
			}},
			Notes: "Workers binding mode is intentionally not part of the Go port.",
		},
		PeerDeps: []string{"github.com/aws/aws-sdk-go-v2/service/s3"},
	},
	"s3": {
		Slug:        "s3",
		Name:        "S3",
		Description: "AWS S3 and S3-compatible object stores.",
		Env: ProviderEnvSpec{
			Config: []string{"bucket"},
			Required: []EnvVar{
				{Key: "AWS_REGION", Aliases: []string{"AWS_DEFAULT_REGION"}, Description: "Bucket region", Secret: false, ReadBy: "gofiles-sdk"},
			},
			CredentialModes: []EnvGroup{{
				Label: "AWS SDK credential chain",
				Vars: []EnvVar{
					{Key: "AWS_ACCESS_KEY_ID", Description: "AWS access key ID", Secret: true, ReadBy: "sdk-chain"},
					{Key: "AWS_SECRET_ACCESS_KEY", Description: "AWS secret access key", Secret: true, ReadBy: "sdk-chain"},
				},
			}},
			Optional: []EnvVar{
				{Key: "AWS_SESSION_TOKEN", Description: "AWS session token", Secret: true, ReadBy: "sdk-chain"},
			},
		},
		PeerDeps: []string{"github.com/aws/aws-sdk-go-v2/service/s3"},
	},
	"s3-compatible": {
		Slug:        "s3-compatible",
		Name:        "S3 Compatible",
		Description: "Generic S3-compatible object store using a custom endpoint.",
		Env: ProviderEnvSpec{
			Config: []string{"bucket", "region", "endpoint"},
			CredentialModes: []EnvGroup{{
				Label: "Access key",
				Vars: []EnvVar{
					{Key: "S3_COMPATIBLE_ACCESS_KEY_ID", Description: "S3-compatible access key ID", Secret: true, ReadBy: "gofiles-sdk"},
					{Key: "S3_COMPATIBLE_SECRET_ACCESS_KEY", Description: "S3-compatible secret access key", Secret: true, ReadBy: "gofiles-sdk"},
				},
			}},
		},
		PeerDeps: []string{"github.com/aws/aws-sdk-go-v2/service/s3"},
	},
	"supabase": {
		Slug:        "supabase",
		Name:        "Supabase Storage",
		Description: "Supabase Storage via the Storage HTTP API.",
		Env: ProviderEnvSpec{
			Config: []string{"bucket"},
			Required: []EnvVar{
				{Key: "SUPABASE_URL", Aliases: []string{"NEXT_PUBLIC_SUPABASE_URL"}, Description: "Supabase project URL", Secret: false, ReadBy: "gofiles-sdk"},
			},
			CredentialModes: []EnvGroup{{
				Label: "API key",
				Vars: []EnvVar{
					{Key: "SUPABASE_SERVICE_ROLE_KEY", Description: "Supabase service role key", Secret: true, ReadBy: "gofiles-sdk"},
				},
			}},
			Optional: []EnvVar{
				{Key: "SUPABASE_KEY", Description: "Alternative Supabase API key", Secret: true, ReadBy: "gofiles-sdk"},
				{Key: "NEXT_PUBLIC_SUPABASE_ANON_KEY", Description: "Anon key for public bucket use cases", Secret: true, ReadBy: "gofiles-sdk"},
			},
			Notes: "Buckets must already exist. Use a service role key for writes to RLS-protected buckets.",
		},
	},
	"uploadthing": {
		Slug:        "uploadthing",
		Name:        "UploadThing",
		Description: "UploadThing UFS API using custom IDs as files-sdk keys.",
		Env: ProviderEnvSpec{
			CredentialModes: []EnvGroup{{
				Label: "API token",
				Vars: []EnvVar{
					{Key: "UPLOADTHING_TOKEN", Description: "UploadThing token", Secret: true, ReadBy: "gofiles-sdk"},
				},
			}},
		},
	},
	"vercel-blob": {
		Slug:        "vercel-blob",
		Name:        "Vercel Blob",
		Description: "Vercel Blob via the Blob HTTP API.",
		Env: ProviderEnvSpec{
			Config: []string{"access"},
			CredentialModes: []EnvGroup{
				{
					Label: "OIDC",
					Vars: []EnvVar{
						{Key: "VERCEL_OIDC_TOKEN", Description: "Vercel OIDC token", Secret: true, ReadBy: "gofiles-sdk"},
						{Key: "BLOB_STORE_ID", Description: "Vercel Blob store ID", Secret: false, ReadBy: "gofiles-sdk"},
					},
				},
				{
					Label: "Read-write token",
					Vars: []EnvVar{
						{Key: "BLOB_READ_WRITE_TOKEN", Description: "Vercel Blob read-write token", Secret: true, ReadBy: "gofiles-sdk"},
					},
				},
			},
			Notes: "OIDC is preferred on Vercel when both VERCEL_OIDC_TOKEN and BLOB_STORE_ID are available. Token authentication is used as the fallback.",
		},
	},
}

Functions

func IsCode

func IsCode(err error, code ErrorCode) bool

Types

type ActionEvent

type ActionEvent struct {
	Type     ActionType
	Key      string
	Keys     []string
	From     string
	To       string
	Duration time.Duration
	Status   string
	Result   any
	Error    *Error
}

type ActionType

type ActionType string
const (
	ActionUpload          ActionType = "upload"
	ActionDownload        ActionType = "download"
	ActionHead            ActionType = "head"
	ActionExists          ActionType = "exists"
	ActionDelete          ActionType = "delete"
	ActionCopy            ActionType = "copy"
	ActionMove            ActionType = "move"
	ActionList            ActionType = "list"
	ActionURL             ActionType = "url"
	ActionSignedUploadURL ActionType = "signedUploadUrl"
)

type AdapterCapabilities

type AdapterCapabilities struct {
	RangeRead      bool
	UploadProgress bool
	Delimiter      bool
	Metadata       bool
	CacheControl   bool
	Multipart      bool
	Resumable      bool
	ServerSideCopy bool
	SignedURL      SignedURLCapability
}

type Body

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

func BodyWithProgress

func BodyWithProgress(body Body, report func(UploadProgress)) Body

func BytesBody

func BytesBody(data []byte) Body

func FileBody

func FileBody(path string) Body

func NewBodyFromReadCloser

func NewBodyFromReadCloser(open func(context.Context) (io.ReadCloser, error), size int64, sizeKnown bool, contentType string, replayable bool) Body

func ReaderBody

func ReaderBody(reader io.Reader) Body

func StringBody

func StringBody(value string) Body

func (Body) ContentType

func (b Body) ContentType() string

func (Body) Open

func (b Body) Open(ctx context.Context) (io.ReadCloser, error)

func (Body) ReadAll

func (b Body) ReadAll(ctx context.Context) ([]byte, error)

func (Body) Replayable

func (b Body) Replayable() bool

func (Body) Size

func (b Body) Size() (int64, bool)

type BulkError

type BulkError struct {
	Key   string
	Error *Error
}

type BulkOptions

type BulkOptions struct {
	Concurrency int
	StopOnError bool
}

type ByteRange

type ByteRange struct {
	Start int64
	End   *int64
}

type Client

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

func MustNew

func MustNew(opts Options) *Client

func New

func New(opts Options) (*Client, error)

func (*Client) Adapter

func (c *Client) Adapter() Adapter

func (*Client) Capabilities

func (c *Client) Capabilities() AdapterCapabilities

func (*Client) Copy

func (c *Client) Copy(ctx context.Context, from string, to string, opts OperationOptions) error

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, key string, opts OperationOptions) error

func (*Client) DeleteMany

func (c *Client) DeleteMany(ctx context.Context, keys []string, opts DeleteManyOptions) (DeleteManyResult, error)

func (*Client) Download

func (c *Client) Download(ctx context.Context, key string, opts DownloadOptions) (StoredFile, error)

func (*Client) DownloadMany

func (c *Client) DownloadMany(ctx context.Context, keys []string, opts DownloadManyOptions) (DownloadManyResult, error)

func (*Client) Exists

func (c *Client) Exists(ctx context.Context, key string, opts OperationOptions) (bool, error)

func (*Client) ExistsMany

func (c *Client) ExistsMany(ctx context.Context, keys []string, opts BulkOptions) (ExistsManyResult, error)

func (*Client) File

func (c *Client) File(key string) FileHandle

func (*Client) Head

func (c *Client) Head(ctx context.Context, key string, opts OperationOptions) (StoredFile, error)

func (*Client) HeadMany

func (c *Client) HeadMany(ctx context.Context, keys []string, opts BulkOptions) (HeadManyResult, error)

func (*Client) List

func (c *Client) List(ctx context.Context, opts ListOptions) (ListResult, error)

func (*Client) ListAll

func (c *Client) ListAll(ctx context.Context, opts ListOptions, yield func(StoredFile) error) error

func (*Client) Move

func (c *Client) Move(ctx context.Context, from string, to string, opts OperationOptions) error

func (*Client) Prefix

func (c *Client) Prefix() string

func (*Client) Raw

func (c *Client) Raw() any

func (*Client) ReadOnly

func (c *Client) ReadOnly() *Client

func (*Client) Search

func (c *Client) Search(ctx context.Context, pattern string, opts SearchOptions, yield func(StoredFile) error) error

func (*Client) SignedUploadURL

func (c *Client) SignedUploadURL(ctx context.Context, key string, opts SignedUploadOptions) (SignedUpload, error)

func (*Client) URL

func (c *Client) URL(ctx context.Context, key string, opts URLOptions) (string, error)

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, key string, body Body, opts UploadOptions) (UploadResult, error)

func (*Client) UploadMany

func (c *Client) UploadMany(ctx context.Context, items []UploadManyItem, opts UploadManyOptions) (UploadManyResult, error)

type DeleteManyAdapter

type DeleteManyAdapter interface {
	DeleteMany(context.Context, []string, DeleteManyOptions) (DeleteManyResult, error)
}

type DeleteManyError

type DeleteManyError struct {
	Key   string
	Error *Error
}

type DeleteManyOptions

type DeleteManyOptions struct {
	Concurrency int
	StopOnError bool
}

type DeleteManyResult

type DeleteManyResult struct {
	Deleted []string
	Errors  []DeleteManyError
}

type DownloadManyOptions

type DownloadManyOptions struct {
	BulkOptions
	Range *ByteRange
}

type DownloadManyResult

type DownloadManyResult struct {
	Downloaded []StoredFile
	Errors     []BulkError
}

type DownloadOptions

type DownloadOptions struct {
	OperationOptions
	Range *ByteRange
}

type EnvGroup

type EnvGroup struct {
	Label string
	Vars  []EnvVar
}

type EnvVar

type EnvVar struct {
	Key         string
	Aliases     []string
	Description string
	Secret      bool
	ReadBy      string
}

func GetSecretEnvVars

func GetSecretEnvVars(slug string) []EnvVar

func ListEnvVars

func ListEnvVars(slug string) []EnvVar

type Error

type Error struct {
	Code      ErrorCode
	Message   string
	Cause     error
	Aborted   bool
	TimedOut  bool
	Permanent bool
}

func NewError

func NewError(code ErrorCode, message string, cause error) *Error

func NewPermanentError

func NewPermanentError(code ErrorCode, message string, cause error) *Error

func TimeoutError

func TimeoutError(timeoutLabel string) *Error

func WrapError

func WrapError(err error, fallback ErrorCode) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorCode

type ErrorCode string
const (
	ErrNotFound     ErrorCode = "NotFound"
	ErrUnauthorized ErrorCode = "Unauthorized"
	ErrConflict     ErrorCode = "Conflict"
	ErrReadOnly     ErrorCode = "ReadOnly"
	ErrProvider     ErrorCode = "Provider"
)

type ErrorEvent

type ErrorEvent struct {
	Type     ActionType
	Key      string
	Keys     []string
	From     string
	To       string
	Duration time.Duration
	Error    *Error
}

type ExistsManyResult

type ExistsManyResult struct {
	Existing []string
	Missing  []string
	Errors   []BulkError
}

type FileHandle

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

func (FileHandle) CopyFrom

func (f FileHandle) CopyFrom(ctx context.Context, source string, opts OperationOptions) error

func (FileHandle) CopyTo

func (f FileHandle) CopyTo(ctx context.Context, destination string, opts OperationOptions) error

func (FileHandle) Delete

func (f FileHandle) Delete(ctx context.Context, opts OperationOptions) error

func (FileHandle) Download

func (f FileHandle) Download(ctx context.Context, opts DownloadOptions) (StoredFile, error)

func (FileHandle) Exists

func (f FileHandle) Exists(ctx context.Context, opts OperationOptions) (bool, error)

func (FileHandle) Head

func (FileHandle) Key

func (f FileHandle) Key() string

func (FileHandle) MoveFrom

func (f FileHandle) MoveFrom(ctx context.Context, source string, opts OperationOptions) error

func (FileHandle) MoveTo

func (f FileHandle) MoveTo(ctx context.Context, destination string, opts OperationOptions) error

func (FileHandle) SignedUploadURL

func (f FileHandle) SignedUploadURL(ctx context.Context, opts SignedUploadOptions) (SignedUpload, error)

func (FileHandle) URL

func (f FileHandle) URL(ctx context.Context, opts URLOptions) (string, error)

func (FileHandle) Upload

func (f FileHandle) Upload(ctx context.Context, body Body, opts UploadOptions) (UploadResult, error)

type Handler

type Handler func(context.Context, Operation) (any, error)

type HeadManyResult

type HeadManyResult struct {
	Files  []StoredFile
	Errors []BulkError
}

type Hooks

type Hooks struct {
	OnAction func(ActionEvent)
	OnError  func(ErrorEvent)
	OnRetry  func(RetryEvent)
}

type ListOptions

type ListOptions struct {
	OperationOptions
	Prefix    string
	Cursor    string
	Limit     int32
	Delimiter string
}

type ListResult

type ListResult struct {
	Items    []StoredFile
	Prefixes []string
	Cursor   string
}

type Middleware

type Middleware func(context.Context, Operation, Handler) (any, error)

func Handlers

func Handlers(handlers map[OperationKind]Middleware) Middleware

type MoveAdapter

type MoveAdapter interface {
	Move(context.Context, string, string, OperationOptions) error
}

type MultipartOptions

type MultipartOptions struct {
	PartSize    int64
	Concurrency int
}

type Operation

type Operation struct {
	Kind                OperationKind
	Key                 string
	Keys                []string
	From                string
	To                  string
	Body                Body
	Bulk                bool
	UploadOptions       UploadOptions
	DownloadOptions     DownloadOptions
	OperationOptions    OperationOptions
	ListOptions         ListOptions
	URLOptions          URLOptions
	SignedUploadOptions SignedUploadOptions
}

type OperationKind

type OperationKind string
const (
	OperationUpload          OperationKind = "upload"
	OperationDownload        OperationKind = "download"
	OperationHead            OperationKind = "head"
	OperationExists          OperationKind = "exists"
	OperationDelete          OperationKind = "delete"
	OperationCopy            OperationKind = "copy"
	OperationMove            OperationKind = "move"
	OperationList            OperationKind = "list"
	OperationURL             OperationKind = "url"
	OperationSignedUploadURL OperationKind = "signedUploadUrl"
)

type OperationOptions

type OperationOptions struct {
	Timeout time.Duration
	Retries *RetryOptions
}

type Options

type Options struct {
	Adapter    Adapter
	Prefix     string
	ReadOnly   bool
	Timeout    time.Duration
	Retries    *RetryOptions
	Hooks      Hooks
	Middleware []Middleware
}

type PartMeta

type PartMeta struct {
	PartNumber int
	Size       int64
	ETag       string
}

type Provider

type Provider struct {
	Slug        string
	Name        string
	Description string
	Env         ProviderEnvSpec
	PeerDeps    []string
}

func GetProvider

func GetProvider(slug string) (Provider, bool)

type ProviderEnvSpec

type ProviderEnvSpec struct {
	Config          []string
	CredentialModes []EnvGroup
	Required        []EnvVar
	Optional        []EnvVar
	Notes           string
}

type ResumableAdapter

type ResumableAdapter interface {
	ResumableUpload(context.Context, string, ResumableUploadOptions) (ResumableDriver, error)
}

type ResumablePart

type ResumablePart struct {
	PartNumber int
	Offset     int64
	Data       []byte
}

type ResumableProbe

type ResumableProbe struct {
	NextOffset int64
	Parts      []PartMeta
}

type ResumableSession

type ResumableSession struct {
	Provider    string
	Key         string
	Bucket      string
	UploadID    string
	PartSize    int64
	ContentType string
	TempPath    string
	Parts       []PartMeta
}

type ResumableUploadMeta

type ResumableUploadMeta struct {
	Key          string
	Size         int64
	ContentType  string
	CacheControl string
	Metadata     map[string]string
	PartSize     int64
}

type ResumableUploadOptions

type ResumableUploadOptions struct {
	ContentType  string
	CacheControl string
	Metadata     map[string]string
	Multipart    *MultipartOptions
}

type RetryBackoffContext

type RetryBackoffContext struct {
	Attempt int
	Error   *Error
}

type RetryEvent

type RetryEvent struct {
	Type       ActionType
	Key        string
	From       string
	To         string
	Attempt    int
	MaxRetries int
	Delay      time.Duration
	Error      *Error
}

type RetryOptions

type RetryOptions struct {
	Max     int
	Backoff func(RetryBackoffContext) time.Duration
}

type SearchMatch

type SearchMatch string
const (
	SearchGlob      SearchMatch = "glob"
	SearchRegex     SearchMatch = "regex"
	SearchSubstring SearchMatch = "substring"
	SearchExact     SearchMatch = "exact"
)

type SearchOptions

type SearchOptions struct {
	OperationOptions
	Prefix          string
	Limit           int32
	MaxResults      int
	Match           SearchMatch
	CaseInsensitive bool
}

type SignedURLCapability

type SignedURLCapability struct {
	Supported    bool
	MaxExpiresIn time.Duration
}

type SignedUpload

type SignedUpload struct {
	Method  string
	URL     string
	Headers map[string]string
	Fields  map[string]string
}

type SignedUploadOptions

type SignedUploadOptions struct {
	OperationOptions
	ExpiresIn   time.Duration
	ContentType string
	MaxSize     *int64
	MinSize     *int64
}

type StoredFile

type StoredFile struct {
	Key          string
	Name         string
	Size         int64
	ContentType  string
	LastModified time.Time
	ETag         string
	Metadata     map[string]string
	// contains filtered or unexported fields
}

func NewStoredFile

func NewStoredFile(meta StoredFileMeta, open func(context.Context) (io.ReadCloser, error)) StoredFile

func NewStoredFileFromBytes

func NewStoredFileFromBytes(meta StoredFileMeta, data []byte) StoredFile

func (StoredFile) Bytes

func (f StoredFile) Bytes(ctx context.Context) ([]byte, error)

func (StoredFile) Open

func (f StoredFile) Open(ctx context.Context) (io.ReadCloser, error)

func (StoredFile) Text

func (f StoredFile) Text(ctx context.Context) (string, error)

type StoredFileMeta

type StoredFileMeta struct {
	Key          string
	Size         int64
	ContentType  string
	LastModified time.Time
	ETag         string
	Metadata     map[string]string
}

type TransferOptions

type TransferOptions struct {
	BulkOptions
	Prefix       string
	TransformKey func(string) string
	Overwrite    *bool
	Limit        int32
	OnProgress   func(TransferProgress)
}

type TransferProgress

type TransferProgress struct {
	Done   int
	Total  int
	Key    string
	Status string
}

type TransferResult

type TransferResult struct {
	Transferred []string
	Skipped     []string
	Errors      []BulkError
}

func Transfer

func Transfer(ctx context.Context, source *Client, dest *Client, opts TransferOptions) (TransferResult, error)

type URLOptions

type URLOptions struct {
	OperationOptions
	ExpiresIn                  time.Duration
	ResponseContentDisposition string
}

type UploadControl

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

func NewUploadControl

func NewUploadControl() *UploadControl

func UploadControlFrom

func UploadControlFrom(session ResumableSession) *UploadControl

func (*UploadControl) Abort

func (c *UploadControl) Abort(ctx context.Context) error

func (*UploadControl) Loaded

func (c *UploadControl) Loaded() int64

func (*UploadControl) Pause

func (c *UploadControl) Pause()

func (*UploadControl) Resume

func (c *UploadControl) Resume()

func (*UploadControl) Session

func (c *UploadControl) Session() (ResumableSession, bool)

func (*UploadControl) Status

func (c *UploadControl) Status() UploadControlStatus

func (*UploadControl) Total

func (c *UploadControl) Total() int64

type UploadControlStatus

type UploadControlStatus string
const (
	UploadControlIdle      UploadControlStatus = "idle"
	UploadControlUploading UploadControlStatus = "uploading"
	UploadControlPaused    UploadControlStatus = "paused"
	UploadControlCompleted UploadControlStatus = "completed"
	UploadControlAborted   UploadControlStatus = "aborted"
	UploadControlError     UploadControlStatus = "error"
)

type UploadManyItem

type UploadManyItem struct {
	Key          string
	Body         Body
	ContentType  string
	CacheControl string
	Metadata     map[string]string
	Multipart    *MultipartOptions
}

type UploadManyOptions

type UploadManyOptions struct {
	BulkOptions
	OnProgress func(string, UploadProgress)
}

type UploadManyResult

type UploadManyResult struct {
	Uploaded []UploadResult
	Errors   []BulkError
}

type UploadOptions

type UploadOptions struct {
	OperationOptions
	ContentType  string
	CacheControl string
	Metadata     map[string]string
	OnProgress   func(UploadProgress)
	Multipart    *MultipartOptions
	Control      *UploadControl
}

type UploadProgress

type UploadProgress struct {
	Loaded int64
	Total  int64
	Known  bool
}

type UploadResult

type UploadResult struct {
	Key          string
	Size         int64
	ContentType  string
	ETag         string
	LastModified time.Time
}

Directories

Path Synopsis
internal
plugins
providers
fs
r2
s3

Jump to

Keyboard shortcuts

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