1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//! [](https://codecov.io/gh/Lurk/cloudinary_rs)
//! [](https://crates.io/crates/cloudinary)
//! [](https://docs.rs/cloudinary)
//!
//! At the moment, there is only half-backed upload and transformation functionality, but if you need more, please let
//! me know.
//!
//! # Upload an image
//!
//! Upload can be done from different sources:
//!
//! - local file
//! - remote file
//! - data url [rfc2397](https://datatracker.ietf.org/doc/html/rfc2397)
//!
//! ## Local file
//!
//! ```rust
//! use std::collections::BTreeSet;
//! use cloudinary::upload::{Source, Upload, OptionalParameters};
//!
//! let upload = Upload::new("api_key".to_string(), "cloud_name".to_string(), "api_secret".to_string() );
//! let options = BTreeSet::from([OptionalParameters::PublicId("file.jpg".to_string())]);
//! let result = upload.image(Source::Path("./image.jpg".into()), &options);
//! ```
//!
//! ## Remote file
//!
//! ```rust
//! use std::collections::BTreeSet;
//! use cloudinary::upload::{Source, Upload, OptionalParameters};
//!
//! let image_url = "https://upload.wikimedia.org/wikipedia/commons/c/ca/1x1.png";
//! let options = BTreeSet::from([OptionalParameters::PublicId("1x1.png".to_string())]);
//! let upload = Upload::new("api_key".to_string(), "cloud_name".to_string(), "api_secret".to_string() );
//! let result = upload.image(Source::Path("./image.jpg".into()), &options);
//! ```
//!
//! ## Data url
//!
//! ```rust
//! use std::collections::BTreeSet;
//! use cloudinary::upload::{Source, Upload, OptionalParameters};
//!
//! let data_url = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";
//! let options = BTreeSet::from([OptionalParameters::PublicId("1x1.png".to_string())]);
//! let upload = Upload::new("api_key".to_string(), "cloud_name".to_string(), "api_secret".to_string() );
//! let result = upload.image(Source::DataUrl(data_url.to_string()), &options);
//! ```
//!
//! # Destroy an asset by publicID
//! ```rust
//! use cloudinary::upload::Upload;
//! let upload = Upload::new("api_key".to_string(), "cloud_name".to_string(), "api_secret".to_string() );
//! let result = upload.destroy("publicID");
//! ```
//!
//! # Transform an image
//!
//! Currently supported transformations:
//! * Resize
//! * Crop
//! * Pad
//!
//! ## Resizing an image:
//!
//! ```rust
//! use cloudinary::transformation::{
//! Transformations::Resize, ResizeMode::ScaleByWidth, Image
//! };
//!
//! let image = Image::new("test".into(), "path/name.png".into())
//! .add_transformation(Resize(ScaleByWidth{ width:100, ar: None, liquid:None}));
//! assert_eq!(
//! image.to_string(),
//! "https://res.cloudinary.com/test/image/upload/c_scale,w_100/path/name.png"
//! );
//! ```
//!
//! ## Cropping an image:
//!
//! ```rust
//! use cloudinary::transformation::{
//! Transformations::Crop, CropMode::FillByWidth, Image
//! };
//!
//! let image = Image::new("test".into(), "path/name.png".into())
//! .add_transformation(Crop(FillByWidth{ width:100, ar: None, gravity: None}));
//!
//! assert_eq!(
//! image.to_string(),
//! "https://res.cloudinary.com/test/image/upload/c_fill,w_100/path/name.png"
//! );
//! ```
//!
//! ## Padding an image:
//!
//! ```rust
//! use cloudinary::transformation::{
//! Transformations::Pad, PadMode::PadByWidth, Image
//! };
//!
//! let image = Image::new("test".into(), "path/name.png".into())
//! .add_transformation(Pad(PadByWidth{ width:100, ar: None, background: None, gravity: None}));
//! assert_eq!(
//! image.to_string(),
//! "https://res.cloudinary.com/test/image/upload/c_pad,w_100/path/name.png"
//! );
//! ```
//!
//! # Get Image from URL
//!
//! Unofficial api. This is not supported by Cloudinary, and can break at any time.
//! Officially you should use public_id that you get from upload.
//!
//! [Support](https://support.cloudinary.com/hc/en-us/community/posts/360006941639-How-to-programmatically-retrieve-public-id-from-URL-)
//!
//! ```rust
//! use cloudinary::transformation::Image;
//! use url::Url;
//! let image = Image::try_from(
//! Url::parse("https://res.cloudinary.com/test/image/upload/path/name.png").unwrap()
//! ).unwrap();
//! assert_eq!(image.to_string(), "https://res.cloudinary.com/test/image/upload/path/name.png");
//! ```
//!
//! # Get a list of all assets with a given tag
//! ```rust
//! # async fn tags(){
//! use cloudinary::tags::get_tags;
//! let tags = get_tags("cloud_name".into(), "tag_name".into()).await;
//! # }
//!
//! ```
//!
//!
//! # Development
//!
//! Due to differences in default upload result shape in different accounts, two sets
//! of credentials must be present in `.env` for tests to succeed.
//!
//! ```sh
//! CLOUDINARY_API_SECRET=***
//! CLOUDINARY_API_KEY=***
//! CLOUDINARY_CLOUD_NAME=***
//!
//! CLOUDINARY_API_SECRET_1=***
//! CLOUDINARY_API_KEY_1=***
//! CLOUDINARY_CLOUD_NAME_1=***
//!```
//!
//! # Minimum supported Rust version
//!
//! The minimum supported Rust version for this crate is 1.65
//!