Skip to main content

rusty_cat/presigned/
upload_part.rs

1use reqwest::header::HeaderMap;
2use reqwest::Method;
3
4/// A single presigned upload part.
5#[derive(Debug, Clone)]
6pub struct PresignedUploadPart {
7    /// Provider-defined part number, usually 1-based for OSS/S3 or 0-based for
8    /// local scheduling.
9    pub part_number: u64,
10    /// Start offset in the full file.
11    pub offset: u64,
12    /// Expected byte size of this part.
13    pub size: u64,
14    /// HTTP method, usually PUT.
15    pub method: Method,
16    /// Full presigned URL for this part.
17    pub url: String,
18    /// Optional provider-specific part identifier, for example Azure block id.
19    pub provider_part_id: Option<String>,
20    /// Optional URL expiration timestamp in Unix seconds.
21    pub expires_at_unix_secs: Option<u64>,
22    /// Headers that must be sent exactly as they were signed.
23    pub headers: HeaderMap,
24}
25
26impl PresignedUploadPart {
27    /// Creates a PUT part with empty headers.
28    pub fn put(part_number: u64, offset: u64, size: u64, url: impl Into<String>) -> Self {
29        Self {
30            part_number,
31            offset,
32            size,
33            method: Method::PUT,
34            url: url.into(),
35            provider_part_id: None,
36            expires_at_unix_secs: None,
37            headers: HeaderMap::new(),
38        }
39    }
40
41    /// Sets provider-specific part identifier, for example Azure block id.
42    pub fn with_provider_part_id(mut self, id: impl Into<String>) -> Self {
43        self.provider_part_id = Some(id.into());
44        self
45    }
46
47    /// Sets URL expiration timestamp in Unix seconds.
48    pub fn with_expires_at_unix_secs(mut self, expires_at_unix_secs: u64) -> Self {
49        self.expires_at_unix_secs = Some(expires_at_unix_secs);
50        self
51    }
52
53    /// Replaces part headers.
54    pub fn with_headers(mut self, headers: HeaderMap) -> Self {
55        self.headers = headers;
56        self
57    }
58}