File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . IO ;
3+ using System . Net . Http ;
4+
5+ public class CatboxUploader
6+ {
7+ // NOTE - You can also return Task<string> instead of void and remove the callback to just await this method
8+ public static async void UploadToCatbox ( string filePath , Action < string > callback )
9+ {
10+ using var client = new HttpClient ( ) ;
11+ client . BaseAddress = new Uri ( "https://catbox.moe/user/api.php" ) ;
12+
13+ using var content = new MultipartFormDataContent ( ) ;
14+
15+ content . Add ( new StringContent ( "fileupload" ) , "reqtype" ) ;
16+ content . Add ( new StreamContent ( File . OpenRead ( filePath ) ) , "fileToUpload" , Path . GetFileName ( filePath ) ) ;
17+
18+ var response = await client . PostAsync ( "" , content ) ;
19+ if ( response . IsSuccessStatusCode )
20+ {
21+ var url = await response . Content . ReadAsStringAsync ( ) ;
22+ callback ( url ) ;
23+ }
24+ else
25+ {
26+ // Handle your failed requests here
27+ }
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments