ruma_client_api/media/create_content.rs
1//! `POST /_matrix/media/*/upload`
2//!
3//! Upload content to the media store.
4
5pub mod v3 {
6 //! `/v3/` ([spec])
7 //!
8 //! [spec]: https://spec.matrix.org/latest/client-server-api/#post_matrixmediav3upload
9
10 use http::header::CONTENT_TYPE;
11 use ruma_common::{
12 OwnedMxcUri,
13 api::{auth_scheme::AccessToken, request, response},
14 metadata,
15 };
16
17 metadata! {
18 method: POST,
19 rate_limited: true,
20 authentication: AccessToken,
21 history: {
22 1.0 => "/_matrix/media/r0/upload",
23 1.1 => "/_matrix/media/v3/upload",
24 }
25 }
26
27 /// Request type for the `create_media_content` endpoint.
28 #[request(error = crate::Error)]
29 pub struct Request {
30 /// The name of the file being uploaded.
31 #[ruma_api(query)]
32 #[serde(skip_serializing_if = "Option::is_none")]
33 pub filename: Option<String>,
34
35 /// The content type of the file being uploaded.
36 #[ruma_api(header = CONTENT_TYPE)]
37 pub content_type: Option<String>,
38
39 /// Should the server return a blurhash or not.
40 ///
41 /// This uses the unstable prefix in
42 /// [MSC2448](https://github.com/matrix-org/matrix-spec-proposals/pull/2448).
43 #[ruma_api(query)]
44 #[cfg(feature = "unstable-msc2448")]
45 #[serde(
46 default,
47 skip_serializing_if = "ruma_common::serde::is_default",
48 rename = "xyz.amorgan.generate_blurhash"
49 )]
50 pub generate_blurhash: bool,
51
52 /// The file contents to upload.
53 #[ruma_api(raw_body)]
54 pub file: Vec<u8>,
55 }
56
57 /// Response type for the `create_media_content` endpoint.
58 #[response(error = crate::Error)]
59 pub struct Response {
60 /// The MXC URI for the uploaded content.
61 pub content_uri: OwnedMxcUri,
62
63 /// The [BlurHash](https://blurha.sh) for the uploaded content.
64 ///
65 /// This uses the unstable prefix in
66 /// [MSC2448](https://github.com/matrix-org/matrix-spec-proposals/pull/2448).
67 #[cfg(feature = "unstable-msc2448")]
68 #[serde(
69 rename = "xyz.amorgan.blurhash",
70 alias = "blurhash",
71 skip_serializing_if = "Option::is_none"
72 )]
73 pub blurhash: Option<String>,
74 }
75
76 impl Request {
77 /// Creates a new `Request` with the given file contents.
78 pub fn new(file: Vec<u8>) -> Self {
79 Self {
80 file,
81 filename: None,
82 content_type: None,
83 #[cfg(feature = "unstable-msc2448")]
84 generate_blurhash: false,
85 }
86 }
87 }
88
89 impl Response {
90 /// Creates a new `Response` with the given MXC URI.
91 pub fn new(content_uri: OwnedMxcUri) -> Self {
92 Self {
93 content_uri,
94 #[cfg(feature = "unstable-msc2448")]
95 blurhash: None,
96 }
97 }
98 }
99}