-
Notifications
You must be signed in to change notification settings - Fork 3
Description
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.