Created
June 16, 2019 12:28
-
-
Save emrekizildas/e9fa4805e41e997dc9309b1605ece5ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<FileResult> DownloadFile(string fileName) | |
{ | |
//MinIO Bağlantısı | |
string endPoint = _config["Minio:Endpoint"]; | |
string accessKey = _config["Minio:Accesskey"]; | |
string secretKey = _config["Minio:SecretKey"]; | |
MinioClient minioClient = new MinioClient(endPoint, accessKey, secretKey); | |
string bucketName = "medium"; | |
MemoryStream memoryStream = new MemoryStream(); | |
try | |
{ | |
//Eğer ilgili bucket altında ismi verilen object yer almıyorsa bu metod bize hata fırlatacaktır. | |
await minioClient.StatObjectAsync(bucketName, fileName); | |
await minioClient.GetObjectAsync(bucketName, fileName, | |
(stream) => | |
{ | |
stream.CopyTo(memoryStream); | |
}); | |
memoryStream.Position = 0; | |
} | |
catch | |
{ | |
} | |
return File(memoryStream, GetContentType(fileName), fileName); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment