I try to use the Minio API to work with S3. I've spent 2 days on this problem, and i can't reach a solution.
Looking for a local upload to my Minio remote place, I tried the sample code given in MinIo SDK documentation :
using System;
using Minio;
using Minio.Exceptions;
using Minio.DataModel;
using System.Threading.Tasks;
namespace FileUploader
{
class FileUpload
{
static void Main(string[] args)
{
var endpoint = "play.min.io";
var accessKey = "Q3AM3UQ867SPQQA43P2F";
var secretKey = "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG";
try
{
var minio = new MinioClient()
.WithEndpoint(endpoint)
.WithCredentials(accessKey, secretKey)
.WithSSL()
.Build();
FileUpload.Run(minio).Wait();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
// File uploader task.
private async static Task Run(MinioClient minio)
{
var bucketName = "mymusic";
var location = "us-east-1";
var objectName = "golden-oldies.zip";
var filePath = "C:\\Users\\username\\Downloads\\golden_oldies.mp3";
var contentType = "application/zip";
try
{
// Upload a file to bucket.
var putObjectArgs = new PutObjectArgs()
.WithBucket(bucketName)
.WithObject(objectName)
.WithFileName(filePath)
.WithContentType(contentType);
await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false);
Console.WriteLine("Successfully uploaded " + objectName );
}
catch (MinioException e)
{
Console.WriteLine("File Upload Error: {0}", e.Message);
}
}
}
}
This is their code; I took it and only change loc of my file / ids / etc...
I can't delete my file after its upload,it is blocked by the process of my program, and its the case until I totally quit it. I tried with more than one file and they all got blocked.
In my soft, I need to detele my files right after the time they are fully uploaded.
How can i achieve this ? Is is just an async misunderstanding from myself or does it come from MinIo lib ?
Just to keep you in touch:
The code i posted worked after some runs (without any reasons / modifications), i haven't any explanation.
However, i wanted to use the sample in a more important project, and I had the same problem of file locked as described in my post (with the exact same code for the upload as shown here).
I spent a lot of time on it and could not explain why it works within a small console app and not in my more important project, even if the code is the same.
So I moved to AWS SDK; it works like a charm !