The Go SDK is currently in experimental status. If you would like to provide feedback, please reach out to us with your suggestions and comments on our Discord.
Go - Bucket.File.Write()
Write a file to a bucket.
import (
"context"
"fmt"
"github.com/nitrictech/go-sdk/nitric"
)
func main() {
bucket, err := nitric.NewBucket("bucket-name").Allow(nitric.BucketWrite)
if err != nil {
return
}
err = bucket.File("cat.png").Write(context.TODO(), []byte("contents"))
if err != nil {
return
}
if err := nitric.Run(); err != nil {
fmt.Println(err)
}
}
Parameters
- Name
ctx
- Required
- Required
- Type
- context
- Description
The context of the call, used for tracing.
- Name
data
- Required
- Required
- Type
- []byte
- Description
The data to write to the file.
Examples
Write a file
import (
"context"
"fmt"
"github.com/nitrictech/go-sdk/nitric"
)
func main() {
bucket, err := nitric.NewBucket("bucket-name").Allow(nitric.BucketWrite)
if err != nil {
return
}
err = bucket.File("cat.png").Write(context.TODO(), []byte("contents"))
if err != nil {
return
}
if err := nitric.Run(); err != nil {
fmt.Println(err)
}
}