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