Methods

Read

Read a file from the bucket.
func (c *Bucket) Read(key string) ([]byte, error)

Parameters

key
string
required
The key/path of the file to read

Returns

[]byte
[]byte
The file contents as a byte slice
error
error
Error if the operation fails
Example:
content, err := client.Image.Read("path/to/file.txt")
if err != nil {
    log.Fatal(err)
}
fmt.Println(string(content))

Write

Write a file to the bucket.
func (c *Bucket) Write(key string, data []byte) error

Parameters

key
string
required
The key/path where the file should be stored
data
[]byte
required
The file contents as a byte slice

Returns

error
error
Error if the operation fails
Example:
err := client.Image.Write("path/to/file.txt", []byte("Hello, World!"))
if err != nil {
    log.Fatal(err)
}

Delete

Delete a file from the bucket.
func (c *Bucket) Delete(key string) error

Parameters

key
string
required
The key/path of the file to delete

Returns

error
error
Error if the operation fails
Example:
err := client.Image.Delete("path/to/file.txt")
if err != nil {
    log.Fatal(err)
}

List

List files in the bucket with a given prefix.
func (c *Bucket) List(prefix string) ([]string, error)

Parameters

prefix
string
required
Filter results to keys starting with this prefix

Returns

[]string
[]string
Slice of file keys matching the prefix
error
error
Error if the operation fails
Example:
// List all files
files, err := client.Image.List("")
if err != nil {
    log.Fatal(err)
}

// List files in a specific directory
docs, err := client.Image.List("documents/")
if err != nil {
    log.Fatal(err)
}

for _, file := range docs {
    fmt.Println(file)
}

Exists

Check if a file exists in the bucket.
func (c *Bucket) Exists(key string) (bool, error)

Parameters

key
string
required
The key/path of the file to check

Returns

bool
bool
True if the file exists, false otherwise
error
error
Error if the operation fails
Example:
exists, err := client.Image.Exists("file.txt")
if err != nil {
    log.Fatal(err)
}

if exists {
    content, _ := client.Image.Read("file.txt")
    // Process content
}

Presigned URLs

Generate presigned URLs for secure file access without exposing credentials.
func (c *Bucket) GetDownloadURL(key string, opts ...PresignUrlOption) (string, error)
func (c *Bucket) GetUploadURL(key string, opts ...PresignUrlOption) (string, error)

Parameters

key
string
required
The key/path of the file
opts
...PresignUrlOption
default:"WithPresignUrlExpiry(5*time.Minute)"
Optional configuration with WithPresignUrlExpiry(duration)

Returns

string
string
The presigned URL for the file
error
error
Error if the operation fails
Example:
// Download URL (default 5 minute expiry)
downloadURL, err := client.Image.GetDownloadURL("file.txt")

// Upload URL with custom expiry (1 hour)
uploadURL, err := client.Image.GetUploadURL("file.txt",
    suga.WithPresignUrlExpiry(time.Hour))