# AWS SDK - .NET

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

## Preparation

* [Download and install](https://dotnet.microsoft.com/en-us/download/dotnet-framework) .NET in your environment.
* [Download and install](https://aws.amazon.com/sdk-for-net/) the AWS SDK for .NET development toolkit.
* [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

`ServiceURL`: <https://endpoint.4everland.co>

`accessKey`: Bucket-Access Keys-API Key

`secretKey`: Bucket-Access Keys-API Secret

```csharp
namespace CreateBucket
{
    using System;
    using System.Threading.Tasks;
    using Amazon.S3;
    using Amazon.S3.Model;

    public class CreateBucket
    {
        public static async Task Main()
        {

            // Specify a name for the new bucket.
            const string newBucketName = "bucketname";

             {
                string accessKey = "4EVERLAND-Bucket-APIKey";
                string secretKey = "4EVERLAND-Bucket-APISecret";
                var config = new AmazonS3Config()
            {
                ServiceURL = string.Format("https://endpoint.4everland.co"),
                ForcePathStyle = true,
            };
            var client = new AmazonS3Client(accessKey, secretKey, config);
            Console.WriteLine($"\nCreating a new bucket, named: {newBucketName}.");

            await CreatingBucketAsync(client, newBucketName);

        }

        static async Task CreatingBucketAsync(IAmazonS3 client, string bucketName)
        {
            try
            {
                var putBucketRequest = new PutBucketRequest
                {
                    BucketName = bucketName,
                    UseClientRegion = true,
                };

                var putBucketResponse = await client.PutBucketAsync(putBucketRequest);

            }
            catch (AmazonS3Exception ex)
            {
                Console.WriteLine($"Error creating bucket: '{ex.Message}'");
            }
        }
    }

}
}
```

### Upload a file

`bucket-name`: Your bucket name

`accessKey`: Bucket-Access Keys-API Key

`secretKey`: Bucket-Access Keys-API Secret

`/path/to/object`: The file path for the file to be uploaded

`objectname`: The name of the file to be uploaded

```csharp
namespace UploadObjectExample
{
    using System;
    using System.Threading.Tasks;
    using Amazon.S3;
    using Amazon.S3.Model;

    public class UploadObject
    {
        private static IAmazonS3 _s3Client;

        private const string bucket-name = "4everland-bucketname";
        private const string objectname = "object-name";

        private static string LOCAL_PATH = "/path/to/object";

        public static async Task Main()
        {
             {
                string accessKey = "4EVERLAND-Bucket-APIKey";
                string secretKey = "4EVERLAND-Bucket-APISecret";
                var config = new AmazonS3Config()
            {
                ServiceURL = string.Format("https://endpoint.4everland.co"),
                ForcePathStyle = true,
            };
            _s3Client = new AmazonS3Client(accessKey, secretKey, config);

            // The method expects the full path, including the file name.
            var path = $"{LOCAL_PATH}/{OBJECT_NAME1}";

            await UploadObjectFromFileAsync(_s3Client, bucket-name, objectname, path);
        }
        static async Task UploadObjectFromFileAsync(
            IAmazonS3 client,
            string bucketName,
            string objectName,
            string filePath)
        {
            try
            {
                var putRequest = new PutObjectRequest
                {
                    BucketName = bucketName,
                    Key = objectName,
                    FilePath = filePath,
                    ContentType = "text/plain",
                };

                putRequest.Metadata.Add("x-amz-meta-title", "FileName");

                PutObjectResponse response = await client.PutObjectAsync(putRequest);
            }
            catch (AmazonS3Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }
        }

    }
}
}
```

### Requesting IPFS CID and Arweave Hash

`Bucket`: The bucket name where the target file is stored

`Key`: The path of the target file

```csharp
var request = new GetObjectMetadataRequest
{
     BucketName = "4everlandbucket",
     Key = "/path/to/4everland/4ever.png"
};
var response = await client.GetObjectMetadataAsync(request);
// 获取文件的metadata
var ipfsHash = response.Metadata["ipfs-hash"];
var arweaveHash = response.Metadata["arweave-hash"];
Console.WriteLine($"IPFS Hash: {ipfsHash}");
//If it is an Arweave type of bucke
 Console.WriteLine($"Arweave Hash: {arweaveHash}");

```

{% 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-.net.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.
