# API Integration

### Installation

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/Filecoin-Titan/titan-storage-sdk
```

### API

```
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/Filecoin-Titan/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.NewStorage(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())
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://titannet.gitbook.io/titan-network-en/tws/titan-storage/how-to-guides/api-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
