aliyun_oss_rs/object/
oss_object.rs

1use super::{
2    AbortUpload, AppendObject, CompleteUpload, CopyObject, CopyToPart, DelObjectTagging, GetObject,
3    GetObjectAcl, GetObjectMeta, GetObjectTagging, GetObjectUrl, GetSymlink, HeadObject,
4    InitUpload, ListParts, PutObject, PutObjectAcl, PutObjectTagging, PutSymlink, RestoreObject,
5    SelectObject, UploadPart, del_object::DelObject,
6};
7use crate::{common::Acl, oss::Oss};
8
9/// OSS object implementing APIs such as uploading and deleting files
10#[derive(Debug, Clone)]
11pub struct OssObject {
12    oss: Oss,
13}
14
15impl OssObject {
16    pub(crate) fn new(mut oss: Oss, object: impl ToString) -> Self {
17        oss.set_object(object);
18        OssObject { oss }
19    }
20    /// Attach a temporary security token for STS authentication
21    pub fn with_security_token(mut self, token: impl Into<String>) -> Self {
22        self.oss.set_security_token(token);
23        self
24    }
25    /// Update the security token in place for reuse
26    pub fn set_security_token(&mut self, token: impl Into<String>) {
27        self.oss.set_security_token(token);
28    }
29    /// Upload a file to OSS
30    pub fn put_object(&self) -> PutObject {
31        PutObject::new(self.oss.clone())
32    }
33    /// Append to a file
34    pub fn append_object(&self) -> AppendObject {
35        AppendObject::new(self.oss.clone())
36    }
37    /// Delete a file
38    pub fn del_object(&self) -> DelObject {
39        DelObject::new(self.oss.clone())
40    }
41    /// Get the object's access URL
42    pub fn get_object_url(&self) -> GetObjectUrl {
43        GetObjectUrl::new(self.oss.clone())
44    }
45    /// Get the object's tag information
46    pub fn get_object_tagging(&self) -> GetObjectTagging {
47        GetObjectTagging::new(self.oss.clone())
48    }
49    /// Get the object's full metadata
50    pub fn head_object(&self) -> HeadObject {
51        HeadObject::new(self.oss.clone())
52    }
53    /// Get the object's meta information
54    pub fn get_object_meta(&self) -> GetObjectMeta {
55        GetObjectMeta::new(self.oss.clone())
56    }
57    /// Get the object's ACL
58    pub fn get_object_acl(&self) -> GetObjectAcl {
59        GetObjectAcl::new(self.oss.clone())
60    }
61    /// Get the object's content
62    pub fn get_object(&self) -> GetObject {
63        GetObject::new(self.oss.clone())
64    }
65    /// Query the object's content using OSS Select
66    pub fn select_object(&self) -> SelectObject {
67        SelectObject::new(self.oss.clone())
68    }
69    /// Copy the object
70    pub fn copy_object(&self, copy_source: &str) -> CopyObject {
71        CopyObject::new(self.oss.clone(), copy_source)
72    }
73    /// Restore the object
74    pub fn restore_object(&self) -> RestoreObject {
75        RestoreObject::new(self.oss.clone())
76    }
77    /// Set the object's ACL
78    pub fn put_object_acl(&self, acl: Acl) -> PutObjectAcl {
79        PutObjectAcl::new(self.oss.clone(), acl)
80    }
81    /// Set the object's tags
82    pub fn put_object_tagging(
83        &self,
84        tags: Vec<(impl ToString, impl ToString)>,
85    ) -> PutObjectTagging {
86        PutObjectTagging::new(self.oss.clone(), tags)
87    }
88    /// Create a symlink
89    pub fn put_symlink(&self, symlink_target: impl ToString) -> PutSymlink {
90        PutSymlink::new(self.oss.clone(), symlink_target)
91    }
92    /// Get the symlink
93    pub fn get_symlink(&self) -> GetSymlink {
94        GetSymlink::new(self.oss.clone())
95    }
96    /// Remove all tags from the object
97    pub fn del_object_tagging(&self) -> DelObjectTagging {
98        DelObjectTagging::new(self.oss.clone())
99    }
100    /// Initialize a multipart upload
101    pub fn multipart_init_upload(&self) -> InitUpload {
102        InitUpload::new(self.oss.clone())
103    }
104    /// Upload a part
105    pub fn multipart_upload_part(&self, part_number: u32, upload_id: impl ToString) -> UploadPart {
106        UploadPart::new(self.oss.clone(), part_number, upload_id)
107    }
108    /// Copy object content to a part
109    pub fn multipart_copy_part(
110        &self,
111        part_number: u32,
112        upload_id: impl ToString,
113        copy_source: impl ToString,
114    ) -> CopyToPart {
115        CopyToPart::new(self.oss.clone(), part_number, upload_id, copy_source)
116    }
117    /// Complete the multipart upload
118    pub fn multipart_complete_upload(&self, upload_id: impl ToString) -> CompleteUpload<'_> {
119        CompleteUpload::new(self.oss.clone(), upload_id)
120    }
121    /// Abort the multipart upload
122    pub fn multipart_abort_upload(&self, upload_id: impl ToString) -> AbortUpload {
123        AbortUpload::new(self.oss.clone(), upload_id)
124    }
125    /// List all successfully uploaded parts for the specified Upload ID
126    pub fn multipart_list_parts(&self, upload_id: impl ToString) -> ListParts {
127        ListParts::new(self.oss.clone(), upload_id)
128    }
129}