Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2a6e5f40f | ||
|
|
801f698dcf | ||
|
|
9c939426ba |
+27
-24
@@ -15,7 +15,7 @@ namespace SimApi.Helpers
|
||||
|
||||
private string ServeUrl { get; }
|
||||
|
||||
private string Bucket { get; }
|
||||
public string Bucket { get; }
|
||||
|
||||
private IHttpContextAccessor HttpContextAccessor { get; }
|
||||
|
||||
@@ -49,40 +49,43 @@ namespace SimApi.Helpers
|
||||
}
|
||||
Mc = mcb.Build();
|
||||
|
||||
bool found = Mc.BucketExistsAsync(new BucketExistsArgs().WithBucket(Bucket)).Result;
|
||||
var found = Mc.BucketExistsAsync(new BucketExistsArgs().WithBucket(Bucket)).Result;
|
||||
if (!found)
|
||||
{
|
||||
Mc.MakeBucketAsync(new MakeBucketArgs().WithBucket(Bucket)).Wait();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取上传的URL
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="expire"></param>
|
||||
/// <returns></returns>
|
||||
public string GetUploadUrl(string path, int expire = 7200)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Mc.PresignedPutObjectAsync(new PresignedPutObjectArgs().WithBucket(Bucket)
|
||||
.WithObject(path).WithExpiry(expire)).Result;
|
||||
}
|
||||
catch (MinioException e)
|
||||
{
|
||||
Console.WriteLine("Error occurred: " + e);
|
||||
return e.Message;
|
||||
}
|
||||
return Mc.PresignedPutObjectAsync(new PresignedPutObjectArgs().WithBucket(Bucket)
|
||||
.WithObject(path).WithExpiry(expire)).Result;
|
||||
}
|
||||
|
||||
public string UploadFile(string path, Stream stream,string contentType = "image/png")
|
||||
/// <summary>
|
||||
/// 获取下载的URL
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="expire"></param>
|
||||
/// <returns></returns>
|
||||
public string GetDownloadUrl(string path, int expire = 600)
|
||||
{
|
||||
try
|
||||
{
|
||||
Mc.PutObjectAsync(new PutObjectArgs().WithBucket(Bucket).WithObject(path).
|
||||
WithObjectSize(stream.Length).WithStreamData(stream).WithContentType(contentType)).Wait();
|
||||
return null;
|
||||
}
|
||||
catch (MinioException e)
|
||||
{
|
||||
Console.WriteLine("Error occurred: " + e);
|
||||
return e.Message;
|
||||
}
|
||||
return Mc.PresignedGetObjectAsync(new PresignedGetObjectArgs().WithBucket(Bucket).WithObject(path)
|
||||
.WithExpiry(expire)).Result;
|
||||
}
|
||||
|
||||
|
||||
public string UploadFile(string path, Stream stream, string contentType = "image/png")
|
||||
{
|
||||
Mc.PutObjectAsync(new PutObjectArgs().WithBucket(Bucket).WithObject(path).WithObjectSize(stream.Length)
|
||||
.WithStreamData(stream).WithContentType(contentType)).Wait();
|
||||
return null;
|
||||
}
|
||||
|
||||
public string FullUrl(string path)
|
||||
|
||||
+1
-1
@@ -198,7 +198,7 @@ namespace SimApi
|
||||
{
|
||||
var options = builder.ApplicationServices.GetRequiredService<SimApiOptions>();
|
||||
|
||||
var logger = builder.ApplicationServices.GetRequiredService<ILogger>();
|
||||
var logger = builder.ApplicationServices.GetRequiredService<ILogger<SimApiOptions>>();
|
||||
|
||||
if (options.EnableForwardHeaders)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user