1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
pub mod unstable {
use ruma_common::{api::ruma_api, IdParseError, MxcUri, ServerName};
ruma_api! {
metadata: {
description: "Upload media to an MXC URI that was created with create_mxc_uri.",
method: PUT,
name: "create_content_async",
unstable_path: "/_matrix/media/unstable/fi.mau.msc2246/upload/:server_name/:media_id",
rate_limited: true,
authentication: AccessToken,
}
request: {
#[ruma_api(path)]
pub media_id: &'a str,
#[ruma_api(path)]
pub server_name: &'a ServerName,
#[ruma_api(raw_body)]
pub file: &'a [u8],
#[ruma_api(header = CONTENT_TYPE)]
pub content_type: Option<&'a str>,
}
response: {}
error: crate::Error
}
impl<'a> Request<'a> {
pub fn new(media_id: &'a str, server_name: &'a ServerName, file: &'a [u8]) -> Self {
Self { media_id, server_name, file, content_type: None }
}
pub fn from_url(url: &'a MxcUri, file: &'a [u8]) -> Result<Self, IdParseError> {
let (server_name, media_id) = url.parts()?;
Ok(Self::new(media_id, server_name, file))
}
}
}