add storage get url

This commit is contained in:
2022-08-17 19:37:39 +08:00
parent 9c939426ba
commit 801f698dcf
+25 -22
View File
@@ -56,33 +56,36 @@ 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)
{ .WithObject(path).WithExpiry(expire)).Result;
return Mc.PresignedPutObjectAsync(new PresignedPutObjectArgs().WithBucket(Bucket)
.WithObject(path).WithExpiry(expire)).Result;
}
catch (MinioException e)
{
Console.WriteLine("Error occurred: " + e);
return e.Message;
}
} }
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 return Mc.PresignedGetObjectAsync(new PresignedGetObjectArgs().WithBucket(Bucket).WithObject(path)
{ .WithExpiry(expire)).Result;
Mc.PutObjectAsync(new PutObjectArgs().WithBucket(Bucket).WithObject(path). }
WithObjectSize(stream.Length).WithStreamData(stream).WithContentType(contentType)).Wait();
return null;
} public string UploadFile(string path, Stream stream, string contentType = "image/png")
catch (MinioException e) {
{ Mc.PutObjectAsync(new PutObjectArgs().WithBucket(Bucket).WithObject(path).WithObjectSize(stream.Length)
Console.WriteLine("Error occurred: " + e); .WithStreamData(stream).WithContentType(contentType)).Wait();
return e.Message; return null;
}
} }
public string FullUrl(string path) public string FullUrl(string path)