chasedredmon / catbox.net Goto Github PK
View Code? Open in Web Editor NEWCatBox.NET is a library for interacting with the CatBox.moe website to upload images and create image albums
License: MIT License
CatBox.NET is a library for interacting with the CatBox.moe website to upload images and create image albums
License: MIT License
I am downloading images and uploading them to catbox from the stream themselves, I do not write to disk so everything is done in memory.
When I download the stream from (in this scenario) Telegram, and then put it in my wrapped class of catbox
public async Task<string?> UploadImageAsync(Stream memoryStream, string fileName) {
return await CatBoxClient.UploadImage(new CatBox.NET.Requests.StreamUploadRequest() {
Stream = memoryStream,
FileName = fileName,
UserHash = UserHash,
});
}
all is well until It is executed. I then get an error
Failed to upload to catbox.moe. Reason: System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.IO.IOException: The response ended prematurely. at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.<SendAsync>g__Core|5_0(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.<SendAsync>g__Core|5_0(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) at CatBox.NET.Client.CatBoxClient.UploadImage(StreamUploadRequest fileUploadRequest, CancellationToken ct) at Http.WrappedCatboxClient.UploadImageAsync(MemoryStream memoryStream, String fileName) in the program`
I have no idea why this happens because when I save the stream to a file the picture is perfect and is exactly what I downloaded. If I upload a file from stream using OpenRead, it works sometimes but not always, but never works well with the image I just saved using the stream. I know that nothing is wrong with how I'm saving the image because if I drag the same file over manually to catbox it uploads it just fine.
Uploading through url also works flawlessly, just not when trying to use a memory stream directly, I always run into the System.IO.IOException: The response ended prematurely.
exception.
Everything is executed as follows
using var stream = new MemoryStream();
var storage = await client.DownloadFileAsync(photo, stream);
var fileName = "";
//some code here that gets the extension of the file
try {
fileName = $"{photo.id}.{extenstion}";
var imageUpload =await Program.WrappedCatboxClient.UploadImage(stream,fileName);
if (imageUpload != null) {
Log.Debug($"Catbox response: {imageUpload}");
if (imageUpload != null) {
var resp = imageUpload; //stuff done here but redacted cause too long
}
}
} catch (Exception ex) {
Log.Error($"Failed to upload to catbox.moe. Reason: {ex.ToString()} with filename {fileName}");
}
The telegram client I am using is WTelegramClient Telegram. But I know it has nothing to do with the telegram client itself, but rather something else (you can prove me wrong if you like, I'd love to know the exact thing I'm doing wrong).
This just confuses me hard. The images are of type jpg.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.