|
|
@ -2,7 +2,6 @@ |
|
|
using Minio.Exceptions; |
|
|
using Minio.Exceptions; |
|
|
using System; |
|
|
using System; |
|
|
using System.IO; |
|
|
using System.IO; |
|
|
using System.Net; |
|
|
|
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
using Volo.Abp.DependencyInjection; |
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
|
|
|
|
|
@ -66,30 +65,28 @@ namespace Volo.Abp.BlobStoring.Minio |
|
|
var blobName = MinioBlobNameCalculator.Calculate(args); |
|
|
var blobName = MinioBlobNameCalculator.Calculate(args); |
|
|
var client = GetMinioClient(args); |
|
|
var client = GetMinioClient(args); |
|
|
var containerName = GetContainerName(args); |
|
|
var containerName = GetContainerName(args); |
|
|
|
|
|
|
|
|
if (!await BlobExistsAsync(client, containerName, blobName)) |
|
|
if (!await BlobExistsAsync(client, containerName, blobName)) |
|
|
{ |
|
|
{ |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var memoryStream = new MemoryStream(); |
|
|
var memoryStream = new MemoryStream(); |
|
|
await client.GetObjectAsync(containerName, blobName, |
|
|
await client.GetObjectAsync(containerName, blobName, stream => |
|
|
(stream) => |
|
|
{ |
|
|
{ |
|
|
if (stream != null) |
|
|
if (stream != null) |
|
|
{ |
|
|
{ |
|
|
stream.CopyTo(memoryStream); |
|
|
stream.CopyTo(memoryStream); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
memoryStream = null; |
|
|
memoryStream = null; |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return memoryStream; |
|
|
return memoryStream; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private MinioClient GetMinioClient(BlobProviderArgs args) |
|
|
private MinioClient GetMinioClient(BlobProviderArgs args) |
|
|
{ |
|
|
{ |
|
|
var configuration = args.Configuration.GetMinioConfiguration(); |
|
|
var configuration = args.Configuration.GetMinioConfiguration(); |
|
|
@ -101,18 +98,14 @@ namespace Volo.Abp.BlobStoring.Minio |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return client; |
|
|
return client; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual async Task CreateBucketIfNotExists(MinioClient client,string containerName) |
|
|
protected virtual async Task CreateBucketIfNotExists(MinioClient client,string containerName) |
|
|
{ |
|
|
{ |
|
|
if (!await client.BucketExistsAsync(containerName)) |
|
|
if (!await client.BucketExistsAsync(containerName)) |
|
|
{ |
|
|
{ |
|
|
await client.MakeBucketAsync(containerName); |
|
|
await client.MakeBucketAsync(containerName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private async Task<bool> BlobExistsAsync(MinioClient client, string containerName , string blobName) |
|
|
private async Task<bool> BlobExistsAsync(MinioClient client, string containerName , string blobName) |
|
|
@ -127,22 +120,25 @@ namespace Volo.Abp.BlobStoring.Minio |
|
|
// else it means that the object exists.
|
|
|
// else it means that the object exists.
|
|
|
// Execution is successful.
|
|
|
// Execution is successful.
|
|
|
await client.StatObjectAsync(containerName, blobName); |
|
|
await client.StatObjectAsync(containerName, blobName); |
|
|
return true; |
|
|
|
|
|
} |
|
|
} |
|
|
catch (MinioException ex) |
|
|
catch (Exception e) |
|
|
{ |
|
|
{ |
|
|
if(ex is ObjectNotFoundException) |
|
|
if (e is ObjectNotFoundException) |
|
|
{ |
|
|
{ |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
else |
|
|
throw ex; |
|
|
{ |
|
|
|
|
|
throw e; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return false; |
|
|
return false; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static string GetContainerName(BlobProviderArgs args) |
|
|
private static string GetContainerName(BlobProviderArgs args) |
|
|
{ |
|
|
{ |
|
|
var configuration = args.Configuration.GetMinioConfiguration(); |
|
|
var configuration = args.Configuration.GetMinioConfiguration(); |
|
|
@ -152,6 +148,5 @@ namespace Volo.Abp.BlobStoring.Minio |
|
|
? args.ContainerName.ToLower() |
|
|
? args.ContainerName.ToLower() |
|
|
: configuration.BucketName.ToLower(); |
|
|
: configuration.BucketName.ToLower(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|