add storage get url

This commit is contained in:
2022-08-17 19:37:39 +08:00
parent 9c939426ba
commit 801f698dcf
+19 -16
View File
@@ -56,34 +56,37 @@ namespace SimApi.Helpers
} }
} }
/// <summary>
/// 获取上传的URL
/// </summary>
/// <param name="path"></param>
/// <param name="expire"></param>
/// <returns></returns>
public string GetUploadUrl(string path, int expire = 7200) public string GetUploadUrl(string path, int expire = 7200)
{
try
{ {
return Mc.PresignedPutObjectAsync(new PresignedPutObjectArgs().WithBucket(Bucket) return Mc.PresignedPutObjectAsync(new PresignedPutObjectArgs().WithBucket(Bucket)
.WithObject(path).WithExpiry(expire)).Result; .WithObject(path).WithExpiry(expire)).Result;
} }
catch (MinioException e)
/// <summary>
/// 获取下载的URL
/// </summary>
/// <param name="path"></param>
/// <param name="expire"></param>
/// <returns></returns>
public string GetDownloadUrl(string path, int expire = 600)
{ {
Console.WriteLine("Error occurred: " + e); return Mc.PresignedGetObjectAsync(new PresignedGetObjectArgs().WithBucket(Bucket).WithObject(path)
return e.Message; .WithExpiry(expire)).Result;
}
} }
public string UploadFile(string path, Stream stream, string contentType = "image/png") public string UploadFile(string path, Stream stream, string contentType = "image/png")
{ {
try Mc.PutObjectAsync(new PutObjectArgs().WithBucket(Bucket).WithObject(path).WithObjectSize(stream.Length)
{ .WithStreamData(stream).WithContentType(contentType)).Wait();
Mc.PutObjectAsync(new PutObjectArgs().WithBucket(Bucket).WithObject(path).
WithObjectSize(stream.Length).WithStreamData(stream).WithContentType(contentType)).Wait();
return null; return null;
} }
catch (MinioException e)
{
Console.WriteLine("Error occurred: " + e);
return e.Message;
}
}
public string FullUrl(string path) public string FullUrl(string path)
{ {