A simple C# Library for UploadServer
You can install this Library via NuGet:
PM> Install-Package CraftingDragon007.KekUploadLibrary
Using the upload client:
usingSystem;usingSystem.IO;usingKekUploadLibrary;classProgram{staticvoidMain(string[]args){varclient=newUploadClient("<Your UploadServer URL>",<Ifyou want to also upload the filenames>);// 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 fileclient.Upload(newUploadItem("<Your File Path>"),<OptionalCancellation Token>,<Optionalwheter or not to use WebSockets for file uploading>);// Upload a streamusing(varstream=newFileStream("<FilePath>",FileMode.Open)){client.Upload(newUploadItem(stream,"<Extension>","<Filename>"));// the filename is optional and must not contain the extension}// Upload a byte arrayclient.Upload(newUploadItem(File.ReadAllBytes("<FilePath>"),"<Extension>","<Filename>"));// 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:
usingSystem;usingSystem.IO;usingKekUploadLibrary;classProgram{staticvoidMain(string[]args){varstream=newChunkedUploadStream("<Extension>","<Your UploadServer URL>","<Filename>");// 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 streamstream.Write(newbyte[]{1,2,3,4,5,6,7,8,9,10},0,10);stream.Flush();// You can do this as often as you wantstream.Write(newbyte[]{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 requeststream.FinishUpload();// This returns the download url of the uploaded bytes// Then you can dispose the streamstream.Dispose();}}Downloading a file:
usingSystem;usingKekUploadLibrary;classProgram{staticvoidMain(string[]args){vardownloadClient=newDownloadClient();downloadClient.ProgressChangedEvent+=(totalFileSize,totalBytesDownloaded,progressPercentage)=>{Console.WriteLine($"Total file size: {totalFileSize}");Console.WriteLine($"Total bytes downloaded: {totalBytesDownloaded}");Console.WriteLine($"Progress percentage: {progressPercentage}");};downloadClient.Download("<Your download url>",newDownloadItem("<Your path>"));}}This Library is licensed under the GNU General Public License v3.0
If you want to contribute to this Library, please open an issue or pull request on GitHub.
Email
Discord: CraftingDragon007#9504