drive_v3/objects/
media.rs

1use std::fmt;
2use serde::{Serialize, Deserialize};
3
4/// The type of upload request to the `/upload` URI.
5///
6/// If you are uploading data with an `/upload` URI, this field is required.
7///
8/// If you are creating a metadata-only file, this field is not required.
9#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
10pub enum UploadType {
11    /// A [simple upload](https://developers.google.com/drive/api/guides/manage-uploads#simple) which allows you to upload a file
12    /// without supplying its metadata.
13    ///
14    /// When you perform a simple upload, basic metadata is created and some attributes are inferred from the file, such as the
15    /// [`mime_type`](super::File::mime_type) or [`modified_time`](super::File::modified_time). You can use a simple upload in
16    /// cases where you have small files and file metadata isn't important.
17    #[default]
18    Media,
19
20    /// A [multipart upload](https://developers.google.com/drive/api/guides/manage-uploads#multipart) which allows to upload
21    /// metadata and data in the same request.
22    ///
23    /// Use this option if the data you send is small enough to upload again, in its entirety, if the connection fails.
24    Multipart,
25
26    /// A [resumable upload](https://developers.google.com/drive/api/guides/manage-uploads#resumable) which allows you to resume
27    /// an upload operation after a communication failure interrupts the flow of data.
28    ///
29    /// Because you don't have to restart large file uploads from the start, resumable uploads can also reduce your bandwidth
30    /// usage if there's a network failure.
31    Resumable,
32}
33
34impl fmt::Display for UploadType {
35    fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
36        let string = match self {
37            Self::Media     => "media",
38            Self::Multipart => "multipart",
39            Self::Resumable => "resumable",
40        };
41
42        write!(f, "{}", string)
43    }
44}
45
46/// Geographic location information stored in the image.
47#[derive(Default, Debug, Clone, Serialize, Deserialize)]
48#[serde(rename_all = "camelCase")]
49pub struct Location {
50    /// The latitude stored in the image.
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub latitude: Option<f64>,
53
54    /// The longitude stored in the image.
55    #[serde(skip_serializing_if = "Option::is_none")]
56    pub longitude: Option<f64>,
57
58    /// The altitude stored in the image.
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub altitude: Option<f64>,
61}
62
63impl fmt::Display for Location {
64    fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
65        let json = serde_json::to_string_pretty(&self)
66            .unwrap_or( format!("unable to parse JSON, this is the debug view:\n{:#?}", self) );
67
68        write!(f, "{}", json)
69    }
70}
71
72impl Location {
73    /// Creates a new, empty instance of this struct.
74    pub fn new() -> Self {
75        Self { ..Default::default() }
76    }
77}
78
79/// Additional metadata about image media, if available.
80#[derive(Default, Debug, Clone, Serialize, Deserialize)]
81#[serde(rename_all = "camelCase")]
82pub struct ImageMediaMetadata {
83    /// Whether a flash was used to create the photo.
84    #[serde(skip_serializing_if = "Option::is_none")]
85    pub flash_used: Option<bool>,
86
87    /// The metering mode used to create the photo.
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub metering_mode: Option<String>,
90
91    /// The type of sensor used to create the photo.
92    #[serde(skip_serializing_if = "Option::is_none")]
93    pub sensor: Option<String>,
94
95    /// The exposure mode used to create the photo.
96    #[serde(skip_serializing_if = "Option::is_none")]
97    pub exposure_mode: Option<String>,
98
99    /// The color space of the photo.
100    #[serde(skip_serializing_if = "Option::is_none")]
101    pub color_space: Option<String>,
102
103    /// The white balance mode used to create the photo.
104    #[serde(skip_serializing_if = "Option::is_none")]
105    pub white_balance: Option<String>,
106
107    /// The width of the image in pixels.
108    #[serde(skip_serializing_if = "Option::is_none")]
109    pub width: Option<i64>,
110
111    /// The height of the image in pixels.
112    #[serde(skip_serializing_if = "Option::is_none")]
113    pub height: Option<i64>,
114
115    /// Geographic location information stored in the image.
116    #[serde(skip_serializing_if = "Option::is_none")]
117    pub location: Option<Location>,
118
119    /// The number of clockwise 90 degree rotations applied from the image's original orientation.
120    #[serde(skip_serializing_if = "Option::is_none")]
121    pub rotation: Option<i64>,
122
123    /// The date and time the photo was taken (EXIF DateTime).
124    #[serde(skip_serializing_if = "Option::is_none")]
125    pub time: Option<String>,
126
127    /// The make of the camera used to create the photo.
128    #[serde(skip_serializing_if = "Option::is_none")]
129    pub camera_make: Option<String>,
130
131    /// The model of the camera used to create the photo.
132    #[serde(skip_serializing_if = "Option::is_none")]
133    pub camera_model: Option<String>,
134
135    /// The length of the exposure, in seconds.
136    #[serde(skip_serializing_if = "Option::is_none")]
137    pub exposure_time: Option<f64>,
138
139    /// The aperture used to create the photo (f-number).
140    #[serde(skip_serializing_if = "Option::is_none")]
141    pub aperture: Option<f64>,
142
143    /// The focal length used to create the photo, in millimeters.
144    #[serde(skip_serializing_if = "Option::is_none")]
145    pub focal_length: Option<f64>,
146
147    /// The ISO speed used to create the photo.
148    #[serde(skip_serializing_if = "Option::is_none")]
149    pub iso_speed: Option<i64>,
150
151    /// The exposure bias of the photo (APEX value).
152    #[serde(skip_serializing_if = "Option::is_none")]
153    pub exposure_bias: Option<f64>,
154
155    /// The smallest f-number of the lens at the focal length used to create the photo (APEX value).
156    #[serde(skip_serializing_if = "Option::is_none")]
157    pub max_aperture_value: Option<f64>,
158
159    /// The distance to the subject of the photo, in meters.
160    #[serde(skip_serializing_if = "Option::is_none")]
161    pub subject_distance: Option<i64>,
162
163    /// The lens used to create the photo.
164    #[serde(skip_serializing_if = "Option::is_none")]
165    pub lens: Option<String>,
166}
167
168impl fmt::Display for ImageMediaMetadata {
169    fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
170        let json = serde_json::to_string_pretty(&self)
171            .unwrap_or( format!("unable to parse JSON, this is the debug view:\n{:#?}", self) );
172
173        write!(f, "{}", json)
174    }
175}
176
177impl ImageMediaMetadata {
178    /// Creates a new, empty instance of this struct.
179    pub fn new() -> Self {
180        Self { ..Default::default() }
181    }
182}
183
184/// Additional metadata about video media.
185///
186/// This may not be available immediately upon upload.
187#[derive(Default, Debug, Clone, Serialize, Deserialize)]
188#[serde(rename_all = "camelCase")]
189pub struct VideoMediaMetadata {
190    /// The width of the video in pixels.
191    #[serde(skip_serializing_if = "Option::is_none")]
192    pub width: Option<i64>,
193
194    /// The height of the video in pixels.
195    #[serde(skip_serializing_if = "Option::is_none")]
196    pub height: Option<i64>,
197
198    /// The duration of the video in milliseconds.
199    #[serde(skip_serializing_if = "Option::is_none")]
200    pub duration_millis: Option<String>,
201}
202
203impl fmt::Display for VideoMediaMetadata {
204    fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
205        let json = serde_json::to_string_pretty(&self)
206            .unwrap_or( format!("unable to parse JSON, this is the debug view:\n{:#?}", self) );
207
208        write!(f, "{}", json)
209    }
210}
211
212impl VideoMediaMetadata {
213    /// Creates a new, empty instance of this struct.
214    pub fn new() -> Self {
215        Self { ..Default::default() }
216    }
217}