Skip to main content

Install

First install the SDK on your project using:
go get -u github.com/blobtrtl3/trtl3-go

Config Client

You can create a default or a custom client, take a look, if you are using the localhost and the default token just use the default client
package main

import "github.com/blobtrtl3/trtl3-go"

func main() {
  // default client
  t3c := trtl3.NewDefaultClient()

  // custom client
  t3cCustom := trtl3.NewClient("http://localhost:7713", "custom-token", 5)
}

Upload Blob

You can upload a blob by using a path or the blob in memory, look up:
// by path
// using relative path, but you also can use the absolute path
path := filepath.Join("your_file.png")

_, err := t3c.UploadBlobByPath("imgs", path)
if err != nil {
  fmt.Println(err)
  return
}

// by in memory blob
var data = []byte("content")
_, err := t3c.UploadBlob("files", bytes.NewReader(data))
if err != nil {
  fmt.Println(err)
  return
}

Find Blobs By Bucket

You can find a list of blobs metadatas by a bucket name
_, err := t3c.FindBlobsByBucket("bucket-name")
if err != nil {
  fmt.Println(err)
  return
}

Find Unique Blob

You can find a unique blob metadata by using the id and the bucket it belongs, look:
_, err := t3c.FindUniqueBlob("bucket-name", "blob-id")
if err != nil {
  fmt.Println(err)
  return
}

Sign Url

You can create signeds urls to expose blobs by other clients, for a limited time interval or a unique access url, it garants you to havemore control about what people access, look:
sign := trtl3.Signature{
  ID: "blob-id",
  Bucket: "bucket-name",
  TTL: 1 * 60, // time in minutes
  Once: true, // if true its a unique access url
}

_, err := t3c.SignUrl(sign)
if err != nil {
  fmt.Println(err)
  return
}

Delete Blob

Delete blob using the bucket and id:
_, err := t3c.DeleteBlob("bucket-name", "blob-id")
if err != nil {
  fmt.Println(err)
  return
}

Download Blob

Download a single blob by using
reader, err := t3c.DownloadBlob("bucket-name", "blob-id")
if err != nil {
  fmt.Println(err)
  return
}
defer reader.Close()

// example: putting the content in a file
// note: if you want to use the extension in the file you can take the blob info first before download it
out, _ := os.Create("out")
defer out.Close()

io.Copy(out, reader)