1//! `PUT /_matrix/media/*/upload/{serverName}/{mediaId}`
2//!
3//! Upload media to an MXC URI that was created with create_mxc_uri.
45pub mod v3 {
6//! `/v3/` ([spec])
7 //!
8 //! [spec]: https://spec.matrix.org/latest/client-server-api/#put_matrixmediav3uploadservernamemediaid
910use http::header::CONTENT_TYPE;
11use ruma_common::{
12 api::{request, response, Metadata},
13 metadata, IdParseError, MxcUri, OwnedServerName,
14 };
1516const 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",
221.7 => "/_matrix/media/v3/upload/:server_name/:media_id",
23 }
24 };
2526/// Request type for the `create_content_async` endpoint.
27#[request(error = crate::Error)]
28pub struct Request {
29/// The server name from the mxc:// URI (the authoritory component).
30#[ruma_api(path)]
31pub server_name: OwnedServerName,
3233/// The media ID from the mxc:// URI (the path component).
34#[ruma_api(path)]
35pub media_id: String,
3637/// The file contents to upload.
38#[ruma_api(raw_body)]
39pub file: Vec<u8>,
4041/// The content type of the file being uploaded.
42#[ruma_api(header = CONTENT_TYPE)]
43pub content_type: Option<String>,
4445/// The name of the file being uploaded.
46#[ruma_api(query)]
47 #[serde(skip_serializing_if = "Option::is_none")]
48pub filename: Option<String>,
49// TODO: How does this and msc2448 (blurhash) interact?
50}
5152/// Response type for the `create_content_async` endpoint.
53#[response(error = crate::Error)]
54pub struct Response {}
5556impl Request {
57/// Creates a new `Request` with the given file contents.
58pub fn new(media_id: String, server_name: OwnedServerName, file: Vec<u8>) -> Self {
59Self { media_id, server_name, file, content_type: None, filename: None }
60 }
6162/// Creates a new `Request` with the given url and file contents.
63pub fn from_url(url: &MxcUri, file: Vec<u8>) -> Result<Self, IdParseError> {
64let (server_name, media_id) = url.parts()?;
65Ok(Self::new(media_id.to_owned(), server_name.to_owned(), file))
66 }
67 }
68}