Shakeer Ahmmed

Shakeer Ahmmed

  • NA
  • 240
  • 10.2k

minio bucket to object file copy into local folder

May 17 2019 4:21 AM
Hi ,
 
  I am try to copy mp3 file minio bucket to local floder ,Could you please help me any one .Below is my code
 
 
using System;
using System.Threading.Tasks;
using System.IO;
using MinioOpeations;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using Minio;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//ClassMinioOperations.DownloadFile();
// ClassMinioOperations.DownloadFile("Minio Bucket name","rL431_mr4376_15-05-2019 04180024.mp3","rL431_mr4376_15-05-2019 04180024.mp3");
DownloadFile("Minio Bucket name", "rL431_mr4376_15-05-2019 04180024.mp3", "rL431_mr4376_15-05-2019 04180024.mp3");
}
public static void DownloadFile(string bucketName, string objectName, string fileName)
{
var endpoint = WebConfigurationManager.AppSettings["endpoint"].ToString();
var accessKey = WebConfigurationManager.AppSettings["accessKey"].ToString();
var secretKey = WebConfigurationManager.AppSettings["secretKey"].ToString();
var AudioFilePath_FromMinio = WebConfigurationManager.AppSettings["AudioFilePath_FromMinio"].ToString();
try
{
// var minio = new MinioClient(endpoint, accessKey, secretKey).WithSSL();
var minio = new MinioClient(endpoint, accessKey, secretKey);
// string DownloadFilePath = HttpContext.Current.Server.MapPath(AudioFilePath_FromMinio); // Web.Config File path.
// AdminRepository adm = new AdminRepository();
string Dpath = @"D:\C#\";
string DownloadFilePath = Dpath; //adm.Destpath(); // Its in Admin Class Method
// DownloadAudioFile.Run(minio).Wait();
Run(minio, bucketName, objectName, fileName, DownloadFilePath).Wait();
}
catch (Exception ex)
{
Console.Out.WriteLine(ex.Message);
}
Console.ReadLine();
}
// Get object in a bucket
public async static Task Run(MinioClient minio, string bucketName, string objectName, string fileName, string DownloadFilePath)
{
try
{
string FilePath = DownloadFilePath + fileName;
// Console.Out.WriteLine("Running example for API: GetObjectAsync");
await minio.GetObjectAsync(bucketName, objectName,
(stream)=>
{
FileStream streamObj = new FileStream(FilePath, FileMode.CreateNew,FileAccess.ReadWrite,FileShare.ReadWrite);
 
stream.CopyTo(streamObj);
});
}
catch (Exception e)
{
Console.WriteLine("[Bucket] Exception: {0}", e);
}
}
}