You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.5 KiB
56 lines
1.5 KiB
using CoviDok.BLL.Storage;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Minio;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace CoviDok.Data.StorageProviders
|
|
{
|
|
public class MinioProvider : IStorageProvider
|
|
{
|
|
private readonly MinioClient Client = null;
|
|
|
|
public static MinioSettings _settings;
|
|
public MinioProvider()
|
|
{
|
|
//var _settings = options.Value;
|
|
Client = new MinioClient(_settings.HostName, _settings.AccessKey, _settings.SecretKey);
|
|
}
|
|
|
|
public async Task CreateNamespace(string ns)
|
|
{
|
|
await Client.MakeBucketAsync(ns);
|
|
}
|
|
|
|
public async Task Download(string ns, string objectname, Action<Stream> callback)
|
|
{
|
|
await Client.GetObjectAsync(ns, objectname, callback);
|
|
}
|
|
|
|
public async Task<bool> NamespaceExists(string ns)
|
|
{
|
|
return await Client.BucketExistsAsync(ns);
|
|
}
|
|
|
|
public async Task Upload(string ns, string objectname, Stream data, long size)
|
|
{
|
|
await Client.PutObjectAsync(ns, objectname, data, size);
|
|
}
|
|
|
|
public async Task<bool> ObjectExists(string ns, string objectname)
|
|
{
|
|
try {
|
|
await Client.StatObjectAsync(ns, objectname);
|
|
return true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|