aliyun_oss_rs/object/
put_symlink.rs

1use crate::{
2    Error,
3    common::{Acl, StorageClass},
4    error::normal_error,
5    request::{Oss, OssRequest},
6};
7use http::Method;
8
9/// Create a symlink
10///
11/// See the [Alibaba Cloud documentation](https://help.aliyun.com/document_detail/45126.html) for details
12pub struct PutSymlink {
13    req: OssRequest,
14}
15impl PutSymlink {
16    pub(super) fn new(oss: Oss, symlink_target: impl ToString) -> Self {
17        let mut req = OssRequest::new(oss, Method::PUT);
18        req.insert_query("symlink", "");
19        req.insert_header("x-oss-symlink-target", symlink_target);
20        PutSymlink { req }
21    }
22    /// Set the file's access permissions
23    pub fn set_acl(mut self, acl: Acl) -> Self {
24        self.req.insert_header("x-oss-object-acl", acl);
25        self
26    }
27    /// Set the file's storage class
28    pub fn set_storage_class(mut self, storage_class: StorageClass) -> Self {
29        self.req.insert_header("x-oss-storage-class", storage_class);
30        self
31    }
32    /// Disallow overwriting files with the same name
33    pub fn forbid_overwrite(mut self) -> Self {
34        self.req.insert_header("x-oss-forbid-overwrite", "true");
35        self
36    }
37    /// Send the request
38    ///
39    pub async fn send(self) -> Result<(), Error> {
40        // Build the HTTP request
41        let response = self.req.send_to_oss()?.await?;
42        // Parse the response
43        let status_code = response.status();
44        match status_code {
45            code if code.is_success() => Ok(()),
46            _ => Err(normal_error(response).await),
47        }
48    }
49}