
3 changed files with 72 additions and 66 deletions
@ -1,57 +1,59 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace CoviDok.BLL.Storage |
|||
{ |
|||
class StorageHandler |
|||
{ |
|||
private readonly IStorageProvider storageProvider; |
|||
|
|||
public StorageHandler(IStorageProvider provider) |
|||
{ |
|||
//Client = new MinioClient(
|
|||
//"192.168.0.160:9000",
|
|||
//"secretaccesskey",
|
|||
//"secretsecretkey");
|
|||
storageProvider = provider; |
|||
} |
|||
|
|||
public async Task<StorageResult> UploadImage(string BucketName, Stream FilePath, long size, string ObjectName) |
|||
{ |
|||
try |
|||
{ |
|||
// Make a bucket on the server, if not already present.
|
|||
bool found = await storageProvider.NamespaceExists(BucketName); |
|||
if (!found) |
|||
{ |
|||
await storageProvider.CreateNamespace(BucketName); |
|||
} |
|||
// Upload a file to bucket.
|
|||
await storageProvider.Upload(BucketName, ObjectName, FilePath, size); |
|||
return new StorageResult(true, ObjectName); |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
return new StorageResult(false, e.Message); |
|||
} |
|||
} |
|||
|
|||
public async Task GetImage(string bucketName, string ImageId, Action<Stream> callback) |
|||
{ |
|||
if (await storageProvider.ObjectExists(bucketName, ImageId)) |
|||
{ |
|||
await storageProvider.Download(bucketName, ImageId, callback); |
|||
} |
|||
else throw new KeyNotFoundException(); |
|||
|
|||
} |
|||
|
|||
public async Task<bool> ImageExists(string bucketName, string ImageId) |
|||
{ |
|||
return await storageProvider.ObjectExists(bucketName, ImageId); |
|||
} |
|||
} |
|||
} |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace CoviDok.BLL.Storage |
|||
{ |
|||
class StorageHandler |
|||
{ |
|||
private readonly IStorageProvider storageProvider; |
|||
|
|||
public StorageHandler(IStorageProvider provider) |
|||
{ |
|||
//Client = new MinioClient(
|
|||
//"192.168.0.160:9000",
|
|||
//"secretaccesskey",
|
|||
//"secretsecretkey");
|
|||
storageProvider = provider; |
|||
} |
|||
|
|||
public async Task<StorageResult> UploadImage(string BucketName, Stream FilePath, long size, string ObjectName) |
|||
{ |
|||
try |
|||
{ |
|||
// Make a bucket on the server, if not already present.
|
|||
bool found = await storageProvider.NamespaceExists(BucketName); |
|||
if (!found) |
|||
{ |
|||
await storageProvider.CreateNamespace(BucketName); |
|||
} |
|||
// Upload a file to bucket.
|
|||
Console.WriteLine("StorageHandler:UploadImage - Uploading " + ObjectName); |
|||
await storageProvider.Upload(BucketName, ObjectName, FilePath, size); |
|||
Console.WriteLine("StorageHandler:UploadImage - Uploaded " + ObjectName); |
|||
return new StorageResult(true, ObjectName); |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
return new StorageResult(false, e.Message); |
|||
} |
|||
} |
|||
|
|||
public async Task GetImage(string bucketName, string ImageId, Action<Stream> callback) |
|||
{ |
|||
if (await storageProvider.ObjectExists(bucketName, ImageId)) |
|||
{ |
|||
await storageProvider.Download(bucketName, ImageId, callback); |
|||
} |
|||
else throw new KeyNotFoundException(); |
|||
|
|||
} |
|||
|
|||
public async Task<bool> ImageExists(string bucketName, string ImageId) |
|||
{ |
|||
return await storageProvider.ObjectExists(bucketName, ImageId); |
|||
} |
|||
} |
|||
} |
|||
|
Loading…
Reference in new issue