Giter Club home page Giter Club logo

Comments (6)

Kuinox avatar Kuinox commented on June 29, 2024

You forgot to reset the position of the memory stream :p.

from catbox.net.

sezonis avatar sezonis commented on June 29, 2024

Unfortunately even with resetting it back to 0 the same error happens

memoryStream.Seek(0, SeekOrigin.Begin); or memoryStream.Position = 0;

Which I find very weird

from catbox.net.

Kuinox avatar Kuinox commented on June 29, 2024

Can you post the code when you reset the position to 0 ?

from catbox.net.

sezonis avatar sezonis commented on June 29, 2024
  public async Task<string?> UploadImageAsync(Stream memoryStream, string fileName) {
            memoryStream.Seek(0, SeekOrigin.Begin);
            return await CatBoxClient.UploadImage(new CatBox.NET.Requests.StreamUploadRequest() {
                Stream = memoryStream,
                FileName = fileName,
                UserHash = UserHash,
            });
        }

Tried both .Position and Seek, also tried instantiating a new memorystream beforehand incase the parameter was making the copy and not persisting on passing it. I must be doing it wrong for sure lol. I have also tried doing it before calling this instead of from within. But console says position is 0 all the time, before calling UploadImageAsync

from catbox.net.

sezonis avatar sezonis commented on June 29, 2024

@Kuinox

After digging deeper and losing my mind for a bit, I have finally figured it out. Yes, my code was functional it had nothing to do with the code. Catbox.moe requires you to have a user agent set otherwise it closes the connection. Perhaps it was a recent addition. I solved this by injecting a user agent into the http client. I think the library should be updated to include a user agent by default. I am not sure if it accepts any user agent so you can give it a unique UA, or if it only accepts known ones like chrome, edge, firefox... etc.

But yea, that's how to fix the problem.

from catbox.net.

ChaseDRedmon avatar ChaseDRedmon commented on June 29, 2024

I'll look into this soon. If that's the case, maybe it's been a recent addition or change to their API because I haven't seen anything related to setting a user agent in the documentation they have.

from catbox.net.

Related Issues (1)

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.