This repository was archived by the owner on Aug 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
85 lines (73 loc) · 2.99 KB
/
Program.cs
File metadata and controls
85 lines (73 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.IO;
using System.Threading.Tasks;
namespace AnonFilesAPI
{
internal class Program
{
static async Task Main()
{
try
{
AnonfilesApiClient anonfilesApiClient = new AnonfilesApiClient();
Console.WriteLine("Choose an option:");
Console.WriteLine("1. Upload a file");
Console.WriteLine("2. Retrieve file information by file ID");
Console.Write("Enter your choice (1 or 2): ");
string choice = Console.ReadLine();
if (choice == "1")
{
Console.Write("Enter the file path to upload: ");
string filePath = Console.ReadLine();
if (!File.Exists(filePath))
{
Console.WriteLine("File not found: " + filePath);
return;
}
UploadResponse uploadResponse = await anonfilesApiClient.UploadFileAsync(filePath);
if (uploadResponse.Status)
{
// File uploaded successfully
var uploadedFile = uploadResponse.Data.File;
Console.WriteLine("File URL: " + uploadedFile.Url.Full);
Console.WriteLine("File ID: " + uploadedFile.Metadata.Id);
Console.ReadKey();
}
else
{
// Handle the error response
Console.WriteLine("Error: " + uploadResponse.Error.Message);
}
}
else if (choice == "2")
{
Console.Write("Enter the file ID to retrieve file information: ");
string fileId = Console.ReadLine();
FileInfoResponse fileInfoResponse = await anonfilesApiClient.GetFileInfoAsync(fileId);
if (fileInfoResponse.Status)
{
// File info retrieved successfully
var file = fileInfoResponse.Data.File;
Console.WriteLine("File URL: " + file.Url.Full);
Console.WriteLine("File Name: " + file.Metadata.Name);
Console.WriteLine("File Size: " + file.Metadata.Size.Readable);
Console.ReadKey();
}
else
{
// Handle the error response
Console.WriteLine("Error: " + fileInfoResponse.Error.Message);
}
}
else
{
Console.WriteLine("Invalid choice. Please choose option 1 or 2.");
}
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
}
}
}
}