parent
c0af24c7fd
commit
6f9566f4d1
|
|
@ -1,4 +1,5 @@
|
||||||
using Microsoft.AspNetCore.Http;
|
using Infrastructure.Helpers;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Minio;
|
using Minio;
|
||||||
using Minio.DataModel;
|
using Minio.DataModel;
|
||||||
|
|
@ -53,6 +54,21 @@ public class MinioService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<string> GetMetaObject(string objectName, string bucketName)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(bucketName))
|
||||||
|
{
|
||||||
|
bucketName = _bucketName;
|
||||||
|
}
|
||||||
|
|
||||||
|
var statArgs = new StatObjectArgs()
|
||||||
|
.WithBucket(bucketName)
|
||||||
|
.WithObject(objectName);
|
||||||
|
var meta = await _minioClient.StatObjectAsync(statArgs);
|
||||||
|
var md5 = meta.MetaData["md5"];
|
||||||
|
return md5; //
|
||||||
|
}
|
||||||
|
|
||||||
public async Task EnsureBucketExistsAsync(string bucketName)
|
public async Task EnsureBucketExistsAsync(string bucketName)
|
||||||
{
|
{
|
||||||
var existsArgs = new BucketExistsArgs().WithBucket(bucketName);
|
var existsArgs = new BucketExistsArgs().WithBucket(bucketName);
|
||||||
|
|
@ -165,11 +181,18 @@ public class MinioService
|
||||||
using var stream = new MemoryStream();
|
using var stream = new MemoryStream();
|
||||||
await file.CopyToAsync(stream);
|
await file.CopyToAsync(stream);
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
|
var md5 = Md5.CalculateStreamMd5(stream);
|
||||||
|
stream.Position = 0;
|
||||||
var putArgs = new PutObjectArgs()
|
var putArgs = new PutObjectArgs()
|
||||||
.WithBucket(bucketName)
|
.WithBucket(bucketName)
|
||||||
.WithObject(objectName)
|
.WithObject(objectName)
|
||||||
.WithStreamData(stream)
|
.WithStreamData(stream)
|
||||||
.WithObjectSize(stream.Length)
|
.WithObjectSize(stream.Length)
|
||||||
|
.WithHeaders(new Dictionary<string, string>()
|
||||||
|
{
|
||||||
|
//x-amz-meta-md5
|
||||||
|
["X-Amz-Meta-Md5"] = md5
|
||||||
|
})
|
||||||
.WithContentType("application/octet-stream");
|
.WithContentType("application/octet-stream");
|
||||||
//.WithContentType(file.ContentType);
|
//.WithContentType(file.ContentType);
|
||||||
await _minioClient.PutObjectAsync(putArgs);
|
await _minioClient.PutObjectAsync(putArgs);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue