I had same problem in C#, this is how I managed to solve:
If you go to the MinIO dashboard, you would be able to download the folder as a zipped file:
Now if you inspect the browser request, it is something like this:
curl '*MINIO_URL*/api/v1/buckets/*BUCKET_NAME*/objects/download?prefix=*PREFIX*'\
-H 'Accept: */*' \
-H 'Accept-Language: en-US,en;q=0.9,fa;q=0.8' \
-H 'Connection: keep-alive' \
-H 'Cookie: token=*TOKEN*' \
-H 'Referer: MINIO_URL/browser/BUCKET_NAME' \
-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36' \
--compressed \
--insecure
Where you should replace MINIO_URL
& BUCKET_NAME
with values of your own, now the TOKEN
value is something you get from dashboard login.
the PREFIX
value is the base64 conversion of the folder path inside minio
This is the code & hope it helps:
public async Task<byte[]> DownloadZippedFolder(string filePath)
{
var httpContent = new StringContent(
content: JsonConvert.SerializeObject(
new
{
accessKey = _minIOSetting.DashboardUserName,
secretKey = _minIOSetting.DashboardPassword
}
),
encoding: Encoding.UTF8,
mediaType: "application/json"
);
try
{
var loginResponse = await _httpClient.PostAsync($"{_minIOSetting.LoginUrl}/api/v1/login", httpContent);
string prefix = Convert.ToBase64String(Encoding.UTF8.GetBytes(filePath));
loginResponse.Headers.TryGetValues("Set-Cookie", out var setCookie);
_httpClient.DefaultRequestHeaders.Add("Cookie", setCookie.First());
string url = _minIOSetting.LoginUrl
+ "/api/v1/buckets/"
+ _minIOSetting.BucketName
+ "/objects/download?prefix="
+ prefix;
var dlreq = await _httpClient.GetAsync(url);
var contentStream = await dlreq.Content.ReadAsStreamAsync();
var memStream = new MemoryStream();
await contentStream.CopyToAsync(memStream);
var bs = memStream.ToArray();
return bs;
}
catch (Exception ex)
{
Console.WriteLine($"min IO error, DownloadZippedFolder: {ex.Message}");
return null;
}
}