Skip to content

A very basic wrapper for uploading files to catbox.moe anonymously with no extra libraries.

License

Notifications You must be signed in to change notification settings

Metalloriff/csharp-catbox-upload

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

csharp-catbox-upload

A very basic wrapper for uploading files to catbox.moe anonymously with no extra libraries.

I couldn't find examples of this anywhere online, so I uploaded the single file to GitHub for anyone else looking for this. Currently, the only functionality is uploading files anonymously, as that's what I was trying to achieve, but I may create a full C# library in the future.

This is just a lazy port from my Unity project. Obviously feel free to move this function into any of your pre-existing classes.

using System;
using System.IO;
using System.Net.Http;
public class CatboxUploader
{
// NOTE - You can also return Task<string> instead of void and remove the callback to just await this method
public static async void UploadToCatbox(string filePath, Action<string> callback)
{
using var client = new HttpClient();
client.BaseAddress = new Uri("https://catbox.moe/user/api.php");
using var content = new MultipartFormDataContent();
content.Add(new StringContent("fileupload"), "reqtype");
content.Add(new StreamContent(File.OpenRead(filePath)), "fileToUpload", Path.GetFileName(filePath));
var response = await client.PostAsync("", content);
if (response.IsSuccessStatusCode)
{
var url = await response.Content.ReadAsStringAsync();
callback(url);
}
else
{
// Handle your failed requests here
}
}
}

About

A very basic wrapper for uploading files to catbox.moe anonymously with no extra libraries.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages