I'm trying to list my backblaze buckets in a console app in c#. I've followed the docs here: AmazonDocs but my app simply ends when trying to call : client.ListBucketsAsync(); in the GetBuckets method. It doesn't catch an error - it just stops.
I'm not sure I've instantiated my client properly and I'm totally flummoxed why the 'DisplayBucketList' method never gets hit.
I've included my code below and throw myself on your mercy.
public class BackBlazeS3
{
public AmazonS3Config s3Config = new AmazonS3Config();
private IAmazonS3 _s3Client;
private string logFileFolder = @"C:\temp\bbi";
private string logFilePath = @"C:\temp\bbi\log.txt";
private string _bucketId = "";
private string _application_key = "";
private string _key_id = "";
public BackBlazeS3(string bucketId, string application_key, string key_id)
{
Console.WriteLine("Log file check");
Directory.CreateDirectory(logFileFolder);
File.CreateText(logFilePath).Dispose();
_application_key = application_key;
_bucketId = bucketId;
_key_id = key_id;
s3Config = new AmazonS3Config() { ServiceURL = "http://s3.us-east-005.backblazeb2.com" };
}
public async Task<bool> StartsHere()
{
try
{
//instantiate client
_s3Client = new AmazonS3Client(_key_id, _application_key, s3Config);
var response = await GetBuckets(_s3Client);
DisplayBucketList(response.Buckets);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return true;
}
/// <summary>
/// Get a list of the buckets owned by the default user.
/// </summary>
/// <param name="client">An initialized Amazon S3 client object.</param>
/// <returns>The response from the ListingBuckets call that contains a
/// list of the buckets owned by the default user.</returns>
public async Task<ListBucketsResponse> GetBuckets(IAmazonS3 client)
{
Console.WriteLine("GetBuckets");
ListBucketsResponse returned = null;
// Get the list of AWS S3 buckets
try
{
returned = await client.ListBucketsAsync();
}
catch (Exception ex)
{
Console.WriteLine($"{ex.Message}.");
}
return returned;
}
/// <summary>
/// This method lists the name and creation date for the buckets in
/// the passed List of S3 buckets.
/// </summary>
/// <param name="bucketList">A List of S3 bucket objects.</param>
public void DisplayBucketList(List<S3Bucket> bucketList)
{
Console.WriteLine("DisplayBucketList");
bucketList
.ForEach(b => Console.WriteLine($"Bucket name: {b.BucketName}, created on: {b.CreationDate}"));
}
}
As above, expecting to get a list of buckets