Upload object

This article shows how to upload object to oss.

Before upoloading objects, you need to buy storage space and authorize it to DeOSS, please refer to Purchase Space and Authorized space.

See all OSS services on the CESS chain.

You can also use the OSS service officially provided by CESS, the address is:http://deoss-pub-gateway.cess.cloud/

Refer to the following code:

package main

import (
	"context"
	"fmt"
	"strings"

	cess "github.com/CESSProject/cess-go-sdk"
)

// Substrate well-known mnemonic:
//
//	https://github.com/substrate-developer-hub/substrate-developer-hub.github.io/issues/613
var MY_MNEMONIC = "bottom drive obey lake curtain smoke basket hold race lonely fit walk"

var RPC_ADDRS = []string{
	"wss://testnet-rpc0.cess.cloud/ws/",
	"wss://testnet-rpc1.cess.cloud/ws/",
	"wss://testnet-rpc2.cess.cloud/ws/",
}

var oss_url = "http://deoss-pub-gateway.cess.cloud/"
var bucket_name = "my-bucket"

func main() {
	sdk, err := cess.New(
		context.Background(),
		cess.ConnectRpcAddrs(RPC_ADDRS),
		cess.Mnemonic(MY_MNEMONIC),
	)
	if err != nil {
		panic(err)
	}
	// upload object
	fmt.Println(sdk.StoreObject(oss_url, strings.NewReader("test data"), bucket_name))
}

Last updated