using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
string fileId = "YOUR_FILE_ID"; // Replace with your file ID
string token = "YOUR_API_TOKEN"; // Replace with your API token
string outputPath = "downloaded_file.pdf"; // Path where to save the downloaded file
string url = $"https://api.roe-ai.com/v1/datasets/files/{fileId}/download/";
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
// Send the request
HttpResponseMessage response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
// For binary files, save the content to a file
byte[] fileBytes = await response.Content.ReadAsByteArrayAsync();
File.WriteAllBytes(outputPath, fileBytes);
Console.WriteLine($"File downloaded successfully to {outputPath}");
// If you want to read as text instead (for text files)
// string responseBody = await response.Content.ReadAsStringAsync();
// Console.WriteLine(responseBody);
}
else
{
Console.WriteLine($"Error: {response.StatusCode}");
string errorContent = await response.Content.ReadAsStringAsync();
Console.WriteLine(errorContent);
}
}
}