· 6 years ago · Jun 27, 2019, 08:58 PM
1public async Task<FileResult> DownloadFile(string fileName)
2 {
3 //MinIO Bağlantısı
4 string endPoint = _config["Minio:Endpoint"];
5 string accessKey = _config["Minio:Accesskey"];
6 string secretKey = _config["Minio:SecretKey"];
7 MinioClient minioClient = new MinioClient(endPoint, accessKey, secretKey);
8
9 string bucketName = "medium";
10
11
12 MemoryStream memoryStream = new MemoryStream();
13 try
14 {
15 //Eğer ilgili bucket altında ismi verilen object yer almıyorsa bu metod bize hata fırlatacaktır.
16 await minioClient.StatObjectAsync(bucketName, fileName);
17
18 await minioClient.GetObjectAsync(bucketName, fileName,
19 (stream) =>
20 {
21 stream.CopyTo(memoryStream);
22 });
23 memoryStream.Position = 0;
24
25 }
26 catch
27 {
28
29 }
30
31 return File(memoryStream, GetContentType(fileName), fileName);
32 }