Go - Bucket.Read()

Read the contents of a file from a bucket.

import (
"context"
"fmt"
"github.com/nitrictech/go-sdk/nitric"
"github.com/nitrictech/go-sdk/nitric/storage"
)
func main() {
bucket := nitric.NewBucket("bucket-name").Allow(storage.BucketRead)
contents, err := bucket.Read(context.TODO(), "cat.png")
if err != nil {
return
}
fmt.Println(contents)
nitric.Run()
}

Parameters

  • Name
    ctx
    Required
    Required
    Type
    context
    Description

    The context of the call, used for tracing.

  • Name
    key
    Required
    Required
    Type
    string
    Description

    The key of the file to read

Examples

Read a file

import (
"context"
"fmt"
"github.com/nitrictech/go-sdk/nitric"
"github.com/nitrictech/go-sdk/nitric/storage"
)
func main() {
bucket := nitric.NewBucket("bucket-name").Allow(storage.BucketRead)
contents, err := bucket.Read(context.TODO(), "cat.png")
if err != nil {
return
}
fmt.Println(contents)
nitric.Run()
}
Last updated on Nov 14, 2024