Giter Club home page Giter Club logo

catbox.net's People

Contributors

chasedredmon avatar formlesstree4 avatar kuinox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

catbox.net's Issues

How to upload files from memorystream?

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.