Titan Storage is an advanced cloud storage application, integrating a visual interface with efficient functionality. Through our SDK, both developers and enterprises can easily integrate and utilize its features.
The test example implements file uploading, listing files that have been uploaded, fetching file, fetching file sharing links, deleting file
1 Register from https://storage.titannet.io, and create API Key
git clone github.com/Titannet-dao/titan-storage-sdk.git
cd /titan-storage-sdk/example
go build
export API_KEY=YOUR-API-KEY
export TITAN_URL=https://api-test1.container1.titannet.io
./example upload /path/to/file
./example list
./example get --cid=your-file-cid --out=/path/to/save/file
./example url your-file-cid
./example delete your-file-cid
To use the titan storage sdk, you'll first need to install Go and set up a Go development environment. Once you have Go installed and configured, you can install the titan storage sdk using Go modules:
go get github.com/Titannet-dao/titan-storage-sdk
UploadFilesWithPath(ctx context.Context, filePath string, progress ProgressFunc) (cid.Cid, error)
UploadFileWithURL(ctx context.Context, url string, progress ProgressFunc) (string, string, error)
UploadStream(ctx context.Context, r io.Reader, name string, progress ProgressFunc) (cid.Cid, error)
ListUserAssets(ctx context.Context, limit, offset int) (*client.ListAssetRecordRsp, error)
Delete(ctx context.Context, rootCID string) error
GetURL(ctx context.Context, rootCID string) (string, error)
GetFileWithCid(ctx context.Context, rootCID string) (io.ReadCloser, error)
package main
import (
"context"
"flag"
"fmt"
"os"
storage "github.com/Titannet-dao/titan-storage-sdk"
)
func main() {
titanURL := os.Getenv("TITAN_URL")
apiKey := os.Getenv("API_KEY")
if len(titanURL) == 0 {
fmt.Println("please set environment variable TITAN_URL, example: export TITAN_URL=Your_titan_url")
return
}
if len(apiKey) == 0 {
fmt.Println("please set environment variable API_KEY, example: export API_KEY=Your_API_KEY")
return
}
flag.Parse()
args := flag.Args()
if len(args) == 0 {
fmt.Println("Please specify the name of the file to be uploaded")
return
}
filePath := args[0]
storage, close, err := storage.Initialize(titanURL, apiKey)
if err != nil {
fmt.Println("NewSchedulerAPI error ", err.Error())
return
}
defer close()
//show upload progress
progress := func(doneSize int64, totalSize int64) {
fmt.Printf("upload %d, total %d\n", doneSize, totalSize)
if doneSize == totalSize {
fmt.Printf("upload success\n")
}
}
root, err := storage.UploadFilesWithPath(context.Background(), filePath, progress)
if err != nil {
fmt.Println("UploadFile error ", err.Error())
return
}
fmt.Printf("upload %s success\n", root.String())
}