ruma_client_api/media/
create_content_async.rs1pub mod v3 {
6 use http::header::CONTENT_TYPE;
11 use ruma_common::{
12 IdParseError, MxcUri, OwnedServerName,
13 api::{auth_scheme::AccessToken, request, response},
14 metadata,
15 };
16
17 metadata! {
18 method: PUT,
19 rate_limited: true,
20 authentication: AccessToken,
21 history: {
22 unstable("fi.mau.msc2246") => "/_matrix/media/unstable/fi.mau.msc2246/upload/{server_name}/{media_id}",
23 1.7 => "/_matrix/media/v3/upload/{server_name}/{media_id}",
24 }
25 }
26
27 #[request(error = crate::Error)]
29 pub struct Request {
30 #[ruma_api(path)]
32 pub server_name: OwnedServerName,
33
34 #[ruma_api(path)]
36 pub media_id: String,
37
38 #[ruma_api(raw_body)]
40 pub file: Vec<u8>,
41
42 #[ruma_api(header = CONTENT_TYPE)]
44 pub content_type: Option<String>,
45
46 #[ruma_api(query)]
48 #[serde(skip_serializing_if = "Option::is_none")]
49 pub filename: Option<String>,
50 }
52
53 #[response(error = crate::Error)]
55 pub struct Response {}
56
57 impl Request {
58 pub fn new(media_id: String, server_name: OwnedServerName, file: Vec<u8>) -> Self {
60 Self { media_id, server_name, file, content_type: None, filename: None }
61 }
62
63 pub fn from_url(url: &MxcUri, file: Vec<u8>) -> Result<Self, IdParseError> {
65 let (server_name, media_id) = url.parts()?;
66 Ok(Self::new(media_id.to_owned(), server_name.to_owned(), file))
67 }
68 }
69}