Open laralove143 opened 2 years ago
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?;
What's the debug output of Request
? (Turn the CreateGuildSticker
struct into one with the TryIntoRequest
trait)
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
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
Is there any updates on this?
I have a fix for this, I will PR it soon.
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