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
If you need to use Arweave storage, you need to create an Arweave bucket. Click to learn more .
To obtain the corresponding API key in the bucket, click to learn more .
Development Examples
Create a bucket
ServiceURL
: https://endpoint.4everland.co
accessKey
: Bucket-Access Keys-API Key
secretKey
: Bucket-Access Keys-API Secret
Copy 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
Copy 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
Copy 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}" );
Last updated 10 months ago