Skip to content

Instantly share code, notes, and snippets.

@emrekizildas
Created June 16, 2019 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emrekizildas/e9fa4805e41e997dc9309b1605ece5ed to your computer and use it in GitHub Desktop.
Save emrekizildas/e9fa4805e41e997dc9309b1605ece5ed to your computer and use it in GitHub Desktop.
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