Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example on create_guild_sticker doesn't work #1954

Open
laralove143 opened this issue Oct 15, 2022 · 6 comments
Open

Example on create_guild_sticker doesn't work #1954

laralove143 opened this issue Oct 15, 2022 · 6 comments
Assignees
Labels
c-http Affects the http crate t-bug Programming error in the library

Comments

@laralove143
Copy link
Member

Running the example at https://api.twilight.rs/twilight_http/request/guild/sticker/struct.CreateGuildSticker.html#examples with a proper token and guild ID returns Error: Response error: status code 400, error: {"message": "Invalid Asset", "code": 50046}, I'm not sure what to put in the file parameter

@laralove143
Copy link
Member Author

laralove143 commented Oct 15, 2022

Actually I think this is a bug, sending the request manually is done successful with the same file

POST https://discord.com/api/v10/guilds/903367565349384202/stickers
Content-Type: multipart/form-data; boundary=WebAppBoundary
Authorization: Bot snip

--WebAppBoundary
Content-Disposition: form-data; name="name"
Content-Type: text/plain

testing sticker
--WebAppBoundary
Content-Disposition: form-data; name="description"
Content-Type: text/plain

testing sticker description
--WebAppBoundary
Content-Disposition: form-data; name="tags"
Content-Type: text/plain

testing,sticker,tags
--WebAppBoundary
Content-Disposition: form-data; name="file"; filename="output.png"
Content-Type: image/png

< /Users/lara/Downloads/output.png
--WebAppBoundary--

but running its (apparently) counterpart in Twilight returns that error

let http = Client::new(env!("TEST_BOT_TOKEN").to_owned());
let guild_id = Id::new(903367565349384202);

http.create_guild_sticker(
    guild_id,
    "testing sticker",
    "testing sticker description",
    "testing,sticker,tags",
    "/Users/lara/Downloads/output.png".as_bytes(),
)?
.exec()
.await?
.model()
.await?;

inlining the file's content doesn't work either

let http = Client::new(env!("TEST_BOT_TOKEN").to_owned());
let guild_id = Id::new(903367565349384202);

http.create_guild_sticker(
    guild_id,
    "testing sticker",
    "testing sticker description",
    "testing,sticker,tags",
    &read("/Users/lara/Downloads/output.png")?,
)?
.exec()
.await?
.model()
.await?;

@vilgotf vilgotf added t-bug Programming error in the library c-http Affects the http crate labels Oct 16, 2022
@vilgotf
Copy link
Member

vilgotf commented Oct 16, 2022

What's the debug output of Request? (Turn the CreateGuildSticker struct into one with the TryIntoRequest trait)

@laralove143
Copy link
Member Author

strings built from utf8 and \r\n's replaced:

Request {
    body: None,
    form: Some(
        Form {
            boundary: "9dD9Oho7LuPcyOe",
            buffer: "
--9dD9Oho7LuPcyOe
Content-Disposition: form-data; name=\"description\"

testing sticker description
--9dD9Oho7LuPcyOe
Content-Disposition: form-data; name=\"file\"

/Users/lara/Downloads/output.png
--9dD9Oho7LuPcyOe
Content-Disposition: form-data; name=\"name\"

testing sticker
--9dD9Oho7LuPcyOe
Content-Disposition: form-data; name=\"tags\"

testing,sticker,tags
--9dD9Oho7LuPcyOe",
        },
    ),
    headers: None,
    method: Post,
    path: "guilds/903367565349384202/stickers",
    ratelimit_path: GuildsIdStickers(
        903367565349384202,
    ),
    use_authorization_token: true,
}

so i think the bug is the file form doesn't mention the filename or content type

@7596ff
Copy link
Contributor

7596ff commented Oct 17, 2022

I was unable to test this at the time and it went untested. So it indeed is untested. I can have a look at it sometime soon

@7596ff 7596ff self-assigned this Oct 17, 2022
@laralove143
Copy link
Member Author

Is there any updates on this?

@zeylahellyer
Copy link
Member

I have a fix for this, I will PR it soon.

@zeylahellyer zeylahellyer assigned zeylahellyer and unassigned 7596ff Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-http Affects the http crate t-bug Programming error in the library
Projects
None yet
Development

No branches or pull requests

4 participants