· 6 years ago · Jun 24, 2019, 05:04 PM
1class Program
2 {
3 static void Main(string[] args)
4 {
5 try
6 {
7 Program p = new Program();
8 p.DownloadFile("SomeFile").Wait();
9 }
10 catch (Exception ex)
11 {
12 Console.Out.WriteLine(ex.Message);
13 }
14 Console.ReadLine();
15 }
16
17 public async Task DownloadFile(string fileName)
18 {
19 string fileLoc = @"DownloadFilePath" + Path.DirectorySeparatorChar + fileName;
20 string minioEndpoint = ConfigurationManager.AppSettings["MinIOServerEndPoint"];
21 string accessKey = ConfigurationManager.AppSettings["MinIOServerAccessKey"];
22 string secretKey = ConfigurationManager.AppSettings["MinIOServerSecretKey"];
23 string bucketName = ConfigurationManager.AppSettings["MinIOStorageBucketName"];
24 string objectName = fileName;
25 try
26 {
27 var minio = new MinioClient(minioEndpoint, accessKey, secretKey);
28 try
29 {
30 // Check of the object exists
31 var found = await minio.StatObjectAsync(bucketName, objectName);
32 // Download the file
33 await minio.GetObjectAsync(bucketName, objectName, fileLoc);
34 }
35 catch (MinioException ex)
36 {
37 Console.WriteLine(ex.Message);
38 }
39 }
40 catch (Exception ex) when (ex != null)
41 {
42 Console.WriteLine(ex.Message);
43 }
44
45 }
46 }
47
48var found = await minio.StatObjectAsync(bucketName, objectName);
49
50[HttpGet]
51 public Data GetData()
52 {
53 try
54 {
55 DataAccessLayer dal = new DataAccessLayer();
56 bool result = dal.DownloadFile("FileName").Wait();
57 return result;
58 }
59 catch (Exception ex) when (ex != null)
60 {
61 throw;
62 }
63 }