4EVERLAND Documents
HomeTwitterDiscordBlogs
  • Welcome to 4EVERLAND
  • Get started
    • Our Features
    • Quick Start Guide
      • Registration
      • Login options
        • MetaMask
        • OKX Wallet
        • Binance Web3 Wallet
        • Bitget Wallet
        • Phantom
        • Petra
        • Lilico
      • Usage Introduction
      • Dashboard stats
      • Account
        • Linking Your EVM Wallet to 4EVERLAND Account
        • Balance Alert
    • Billing and Pricing
      • What is LAND?
      • How to Obtain LAND?
      • Pricing Model
      • Q&As
    • Tokenomics
  • HOSITNG
    • What is Hosting?
      • IPFS Hosting
      • Arweave Hosting
        • Auto-Generation of Manifest
      • Internet Computer Hosting
      • Greenfield Hosting
    • Guides
      • Creating a Deployment
        • With Git
        • With IPFS Hash
        • With a Template
      • Site Deployment
      • Domain Management
        • DNS Setup Guide
        • ENS Setup Guide
        • SNS Setup Guide
          • The gateway: 4sol.xyz
        • SPACE ID Setup Guide
      • Project Setting
        • Git
      • Troubleshooting
      • Common Frameworks
    • Hosting Templates Centre
      • Templates Configuration File
    • Quick Addition
      • Implement Github 4EVER Pin
      • Github Deployment Button
    • Hosting API
      • Create Project API
      • Deploy Project API
      • Get Task Info API
      • IPNS Deployment Update API
    • Hosting CLI
  • Storage
    • Bucket
      • IPFS Bucket
        • Get Root CID - Snapshots
      • Arweave Bucket
        • Path Manifests
          • Instructions for Building Manifest
          • Auto-Generation of Manifest
        • Arweave Tags
        • Unleash Arweave
      • Guides
      • Bucket API - S3 Compatible
        • Coding Examples
          • AWS SDK - Go (Golang)
          • AWS SDK - Java
          • AWS SDK - JavaScript
          • AWS SDK - .NET
          • AWS SDK - PHP
          • AWS SDK - Python
          • AWS SDK - Ruby
        • S3 Tags Instructions
      • 4EVER Security Token Service API
      • Bucket Tools
      • Bucket Gateway Optimizer
    • 4EVER Pin
      • Guides
      • Pinning Services API
      • IPFS Migrator
    • Storage SDK
  • Gateways
    • IPFS Gateway
    • IC Gateway
    • Arweave Gateway
    • Dedicated Gateways
      • Gateway Access Controls
      • Video Streaming
      • IPFS Image Optimizer
    • IPNS Manager
      • IPNS Manager API
  • RPC
    • Guides
    • API Keys
    • JSON Web Token (JWT)
    • What's CUs/CUPS
    • WebSockets
    • Archive Node
    • Debug API
    • Chains RPC
      • BSC / opBNB
      • Ethereum
      • Optimism
      • Polygon
      • Taiko
  • AI
    • AI RPC
      • Quick Start
      • Models
      • API Keys
      • Requests & Responses
      • Parameters
    • 4EVER Chat
  • RaaS - Beta
    • What's Rollups?
    • 4EVER Rollup Stack
  • DePIN
    • 4EVER Network
    • Storage Nodes
  • More
    • Use Cases
      • Livepeer
      • Lens Protocol
      • Optopia.ai
      • Linear Finance
      • Snapshot
      • Tape
      • Taiko
      • Hey.xyz
      • SyncSwap
    • Community
    • Tutorials
    • Security
    • 4EVERLAND FAQ
Powered by GitBook
On this page
  • Preparation
  • Development Examples
  • Install the S3 client
  • Create a bucket
  • Upload a file
  • To retrieve the bucket and file list
  • Requesting IPFS CID and Arweave Hash
  1. Storage
  2. Bucket
  3. Bucket API - S3 Compatible
  4. Coding Examples

AWS SDK - Go (Golang)

Last updated 1 year ago

Please read the following to understand how to use the AWS SDK - Go with the 4EVERLAND Bucket. Combine the AWS SDK API for the Go language with the 4EVERLAND Bucket to achieve file uploads to the IPFS or Arweave storage networks.

Preparation

  • In your development environment, Go.

  • the AWS SDK for Go.

  • a free 4EVERLAND account.

  • If you need to use Arweave storage, you need to create an Arweave bucket. Click to.

  • To obtain the corresponding API key in the bucket, click to.

Development Examples

Install the S3 client

The following code example defines an S3 client and does not return any output. Replace the values in the code below to complete your configuration:

  1. Endpoint:https://endpoint.4everland.co

  2. 4EVERLAND-Bucket-APIKey: Bucket-Access Keys-API key

  3. 4EVERLAND-Bucket-APISecret: Bucket-Access Keys-API Secret

  4. Region: Default filled in with "4everland"

package main
 
import (
        "fmt"
        "github.com/aws/aws-sdk-go/aws"
        "github.com/aws/aws-sdk-go/aws/session"
        "github.com/aws/aws-sdk-go/aws/credentials"
        "github.com/aws/aws-sdk-go/service/s3"
)
 
func main() {
        s3Config := aws.Config{
        Credentials:      credentials.NewStaticCredentials("4EVERLAND-Bucket-APIKey", "4EVERLAND-Bucket-APISecret", ""),
        Endpoint:         aws.String("https://endpoint.4everland.co"),
        Region:           aws.String("4everland"),
}

Create a bucket

bucket:The desired name for creating the bucket

goSession, err := session.NewSessionWithOptions(session.Options{
        Config:  s3Config,
        Profile: "4everland",
})
 
// check if the session was created correctly.
 
if err != nil {
        fmt.Println(err)
}
 
// create a s3 client session
s3Client := s3.New(goSession)
 
// set parameter for bucket name
bucket := aws.String("bucketname")
 
// create a bucket
_, err = s3Client.CreateBucket(&s3.CreateBucketInput{
        Bucket: bucket,
})
 
// print if there is an error
if err != nil {
        fmt.Println(err.Error())
return
}
}

Upload a file

bucket: Your bucket name

/path/to/4everland/4ever.png: The file path for upload

Key: The file name for upload

// create a new session using the config above and profile
goSession, err := session.NewSessionWithOptions(session.Options{
        Config:  s3Config,
        Profile: "4everland",
})
 
// check if the session was created correctly.
 
if err != nil {
        fmt.Println(err)
}
 
// create a s3 client session
s3Client := s3.New(goSession)
 
//set the file path to upload
file, err := os.Open("/path/to/4everland/4ever.png")
if err != nil {
        fmt.Println(err.Error())
return
}
 
defer file.Close()
// create put object input
        putObjectInput := &s3.PutObjectInput{
        Body:   file,
        Bucket: aws.String("4everland-bucketname"),
        Key:    aws.String("object-name"),
}
 
// upload file
_, err = s3Client.PutObject(putObjectInput)
 
// print if there is an error
if err != nil {
        fmt.Println(err.Error())
return
}
}

To retrieve the bucket and file list

listBucketOutPut, err := client.ListBuckets(context.TODO(), &s3.ListBucketsInput{})

if err != nil {
    log.Fatalf("unable ListBuckets: , %v", err)
}
    //listObjectV2
listObjectsV2Output, err := client.ListObjectsV2(context.TODO(), &s3.ListObjectsV2Input{
    Bucket: &bucket,
})

if err != nil {
    log.Fatalf("unable listObjectsV2: , %v", err)
}
fmt.Println(listObjectsV2Output)

Requesting IPFS CID and Arweave Hash

bucket:The bucket name where the target file is stored

objectKey: The path of the target file

var (
    bucket = "4everlandbucket"
    objectKey = "/path/to/4everland/4ever.png"
)
object, err := client.HeadObject(context.Background(), &s3.HeadObjectInput{
    Bucket: &bucket,
    Key:    &objectKey,
})
if err != nil {
    return
}
if err != nil {
    panic(err)
}
fmt.Println("ipfs cid:", object.Metadata["ipfs-hash"])
//If it is an Arweave type of bucket.
fmt.Println("arweave hash:", object.Metadata["arweave-hash"])

If you have any questions, please join our , or send us an email at .

download and install
Download and install
Register
learn more
learn more
Discord server
contact@4everland.org