# 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**

* [Download and install Ruby](https://www.ruby-lang.org/en/downloads/) in your development environment.
* [Download and install](https://github.com/aws/aws-sdk-ruby) the AWS SDK for Ruby in your development environment.
* [Register](https://www.4everland.org/) a free 4EVERLAND account.
* If you need to use Arweave storage, you need to create an Arweave bucket. Click to[ ](https://docs.4everland.org/storage/bucket/bucket-api-s3-compatible)[learn more](https://docs.4everland.org/storage/bucket/guides).
* To obtain the corresponding API key in the bucket, click to[ learn more](https://docs.4everland.org/storage/bucket/bucket-api-s3-compatible).

## 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

```ruby
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

```ruby
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

```ruby
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

```

{% hint style="info" %}
If you have any questions, please join our [Discord server](https://discord.com/invite/Cun2VpsdjF), or send us an email at <contact@4everland.org>.
{% endhint %}


---

# 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://docs.4everland.org/storage/bucket/bucket-api-s3-compatible/coding-examples/aws-sdk-ruby.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.
