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:
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
}
}