AWS SDK for .NET
Learn how to pin files and folders to IPFS using the AWS SDK for .NET.
AWS SDKs (software development kits) help simplify coding and application development by supporting and providing code objects for use with S3-compatible services. There are a variety of different AWS SDKs, each for a different coding language. This guide covers AWS SDK - .NET.
The AWS SDK for .NET includes support for the Unity game engine development framework.
A .car file is a type of compressed archive file that contains multiple files, similar to a ZIP file. .car files are used by the FileCoin and IPFS networks, which utilize the metadata fields to include the IPFS CIDs of each file within the archive.
Read below to learn how to pin files and folders to IPFS using the AWS SDK for .NET.



The following code example uploads an object to the specified IPFS bucket. Replace the following values in the code to match your configuration:
filebase-bucket-name: The Filebase Bucket Name
filebase-access-key: Your Filebase Access Key
filebase-secret-key: Your Filebase Secret Key
/path/to/object: The file path to the object that you want to be uploaded to IPFS
object-name: The desired object name once uploaded
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 = "filebase-bucket-name";
private const string OBJECT_NAME1 = "object-name";
private static string LOCAL_PATH = "/path/to/object";
public static async Task Main()
{
{
string accessKey = "filebase-access-key";
string secretKey = "filebase-secret-key";
var config = new AmazonS3Config()
{
ServiceURL = string.Format("https://s3.filebase.com"),
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, OBJECT_NAME1, 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}");
}
}
}
}
}
git clone https://github.com/web3-storage/ipfs-car
npx ipfs-car
This has been tested with .car archives containing 10,000 or more files. Use any of the following commands, depending on your desired workflow:
ipfs-car --pack path/to/file/or/dir
ipfs-car --pack path/to/files --output path/to/write/ipfs-car.car
The following code example uploads an object to the specified IPFS bucket. Replace the following values in the code to match your configuration:
filebase-bucket-name: The Filebase Bucket Name
filebase-access-key: Your Filebase Access Key
filebase-secret-key: Your Filebase Secret Key
/path/to/object: The file path to the .car file that you want to be uploaded to IPFS
object-name: The desired .car file name once uploaded
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 = "filebase-bucket-name";
private const string OBJECT_NAME1 = "object-name";
private static string LOCAL_PATH = "/path/to/object";
public static async Task Main()
{
{
string accessKey = "filebase-access-key";
string secretKey = "filebase-secret-key";
var config = new AmazonS3Config()
{
ServiceURL = string.Format("https://s3.filebase.com"),
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, OBJECT_NAME1, 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}");
}
}
}
}
}
If you have any questions, please join our Discord server, or send us an email at [email protected]