AWS SDK - Ruby

Please read the following to understand how to use the 4EVERLAND Bucket with AWS SDK - Ruby. This guide outlines the integration of AWS SDK API for Ruby with the 4EVERLAND Bucket to facilitate file uploads to the IPFS or Arweave storage networks.

Preparation

Development Examples

Create a bucket

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

aws_access_key_id: Bucket-Access Keys-API key

aws_secret_access_key: Bucket-Access Keys-API Secret

bucket_name: The desired bucket name to create

require 'aws-sdk-s3'

s3 = Aws::S3::Client.new(
access_key_id: '4EVERLAND-Bucket-APIKey',
secret_access_key: '4EVERLAND-Bucket-APISecret',
region: '4everland',
endpoint: 'https://endpoint.4everland.co'
)

bucket_name = 'new-bucketname'
s3.create_bucket(bucket: bucket_name)

Upload a file

bucket_name: Your bucket name

object_key: The name of the file to be uploaded

object_path: The path of the file to be uploaded

require 'aws-sdk-s3'

s3 = Aws::S3::Client.new(
access_key_id: '4EVERLAND-Bucket-APIKey',
secret_access_key: '4EVERLAND-Bucket-APISecret',
region: '4everland',
endpoint: 'https://endpoint.4everland.co'
)

bucket_name = '4everland-bucketname'
object_key = 'object-name'
object_path = '/path/to/4everland/4ever.png'

File.open(object_path, 'rb') do |file|
s3.put_object(bucket: bucket_name, key: object_key, body: file)
end

Requesting IPFS CID and Arweave Hash

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

aws_access_key_id: Bucket-Access Keys-API Key

aws_secret_access_key: Bucket-Access Keys-API Secret

bucket_name: The bucket name where the target file is stored

object_name: The name of the target file

require 'aws-sdk-s3'
  
Aws3 = Aws::S3::Client.new(
    access_key_id: '4EVERLAND-Bucket-APIKey',
    secret_access_key: '4EVERLAND-Bucket-APISecret',
    region: '4everland',
    endpoint: 'https://endpoint.4everland.co'
)

bucket_name = '4everland-bucketname'
object_name = 'your-object-name'

s3 = Aws3::S3::Resource.new

begin
  obj = s3.bucket(bucket_name).object(object_name)
  metadata = obj.metadata
  ipfs_hash = metadata['ipfs-hash']
  arweave_hash = metadata['arweave-hash']
  puts "IPFS Hash: #{ipfs_hash}"
  #If it is an Arweave type of bucke
  puts "Arweave Hash: #{arweave_hash}"

rescue Aws::S3::Errors::NoSuchKey
  puts "File does not exist"
rescue StandardError => e
  puts "An error occurred:#{e.message}"
end

If you have any questions, please join our Discord server, or send us an email at contact@4everland.org.

Last updated