https://github.com/gamepowerx/kekuploadlibrary
A simple C# Library for UploadServer
https://github.com/gamepowerx/kekuploadlibrary
csharp dotnet library net6 nuget-package uploadclient
Last synced: 2 months ago
JSON representation
A simple C# Library for UploadServer
- Host: GitHub
- URL: https://github.com/gamepowerx/kekuploadlibrary
- Owner: GamePowerX
- License: gpl-3.0
- Created: 2022-03-02T14:51:38.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-01-24T21:01:07.000Z (over 2 years ago)
- Last Synced: 2025-03-25T04:52:22.709Z (over 1 year ago)
- Topics: csharp, dotnet, library, net6, nuget-package, uploadclient
- Language: C#
- Homepage: https://www.nuget.org/packages/CraftingDragon007.KekUploadLibrary/
- Size: 146 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
KekUploadLibrary [](https://github.com/CraftingDragon007/KekUploadLibrary/blob/master/LICENSE) [](https://www.nuget.org/packages/CraftingDragon007.KekUploadLibrary) [](https://www.nuget.org/packages/CraftingDragon007.KekUploadLibrary)
====
A simple C# Library for [UploadServer](https://github.com/KotwOSS/kekupload-server)
# Installation
You can install this Library via NuGet:
```
PM> Install-Package CraftingDragon007.KekUploadLibrary
```
# Usage
Using the upload client:
```C#
using System;
using System.IO;
using KekUploadLibrary;
class Program
{
static void Main(string[] args)
{
var client = new UploadClient("", );
// Diffrent Events are available (Optional)
client.UploadCompleteEvent += (sender, e) => Console.WriteLine("Upload Complete: " + e.FileUrl);
client.UploadChunkCompleteEvent += (sender, e) => Console.WriteLine("Upload progress: {0}/{1}", e.CurrentChunkCount, e.TotalChunkCount);
client.UploadErrorEvent += (sender, e) =>
{
if(e.ErrorResponse != null)
{
Console.WriteLine("Error: " + e.ErrorResponse);
Console.WriteLine("Exception: " + e.Exception);
}else
{
Console.WriteLine("Error: " + e.Exception);
}
};
client.UploadStreamCreateEvent += (sender, e) => Console.WriteLine("Upload Stream created: " + e.UploadStreamId);
// Upload a file
client.Upload(new UploadItem(""), , );
// Upload a stream
using(var stream = new FileStream("", FileMode.Open))
{
client.Upload(new UploadItem(stream, "", "")); // the filename is optional and must not contain the extension
}
// Upload a byte array
client.Upload(new UploadItem(File.ReadAllBytes(""), "", "")); // the filename is optional and must not contain the extension
// The upload method returns the download url of the uploaded file
}
}
```
Using the chunked upload stream:
```C#
using System;
using System.IO;
using KekUploadLibrary;
class Program
{
static void Main(string[] args)
{
var stream = new ChunkedUploadStream("", "", ""); // the filname can be null and must not contain the extension
// Diffrent Events are available (Optional)
stream.UploadChunkCompleteEvent += (sender, e) => Console.WriteLine("Upload progress: {0}/{1}", e.CurrentChunkCount, e.TotalChunkCount);
stream.UploadCompleteEvent += (sender, e) => Console.WriteLine("Upload Complete: " + e.FileUrl);
stream.UploadErrorEvent += (sender, e) =>
{
if(eventArgs.ErrorResponse != null)
{
Console.WriteLine("Error: " + e.ErrorResponse);
Console.WriteLine("Exception: " + e.Exception);
}else
{
Console.WriteLine("Error: " + e.Exception);
}
};
stream.UploadStreamCreateEvent += (sender, e) => Console.WriteLine("Upload Stream created: " + e.UploadStreamId);
// Now you can write everything you want to the stream
// The stream will be chunked and uploaded to the upload server
// It will only be uploaded, when you flush the stream
stream.Write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 0, 10);
stream.Flush();
// You can do this as often as you want
stream.Write(new byte[] { 2, 5, 3, 4, 5, 0, 7, 8, 4, 10 }, 0, 10);
stream.Flush();
// When you are done, you can finish the upload with a final request
stream.FinishUpload(); // This returns the download url of the uploaded bytes
// Then you can dispose the stream
stream.Dispose();
}
}
```
Downloading a file:
```C#
using System;
using KekUploadLibrary;
class Program
{
static void Main(string[] args)
{
var downloadClient = new DownloadClient();
downloadClient.ProgressChangedEvent += (totalFileSize, totalBytesDownloaded, progressPercentage) =>
{
Console.WriteLine($"Total file size: {totalFileSize}");
Console.WriteLine($"Total bytes downloaded: {totalBytesDownloaded}");
Console.WriteLine($"Progress percentage: {progressPercentage}");
};
downloadClient.Download("", new DownloadItem(""));
}
}
```
# License
This Library is licensed under the [GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.en.html)
# Contributing
If you want to contribute to this Library, please open an issue or pull request on GitHub.
# Contributors
- [CraftingDragon007](https://github.com/CraftingDragon007)
- [KekOnTheWorld](https://github.com/KekOnTheWorld)
# Contact
[Email](mailto:craftingdragon007@outlook.com)
Discord: CraftingDragon007#9504