-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upload from URL.
- Loading branch information
Showing
7 changed files
with
132 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/target | ||
/Cargo.lock | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use dotenv::dotenv; | ||
use std::env::var; | ||
|
||
use crate::{ | ||
upload::result::UploadResult::{Error, Success}, | ||
upload::UploadOptions, | ||
Cloudinary, Source, | ||
}; | ||
|
||
#[tokio::test] | ||
async fn test_image_upload_from_url() { | ||
dotenv().ok(); | ||
let api_secret = var("CLOUDINARY_API_SECRET").expect("enviroment variables not set"); | ||
let api_key = var("CLOUDINARY_API_KEY").expect("enviroment variables not set"); | ||
let cloud_name = var("CLOUDINARY_CLOUD_NAME").expect("enviroment variables not set"); | ||
|
||
let cloudinary = Cloudinary::new(api_key, cloud_name, api_secret); | ||
let image_url = "https://upload.wikimedia.org/wikipedia/commons/c/ca/1x1.png"; | ||
let public_id = "image_upload_from_url"; | ||
|
||
let options = UploadOptions::new() | ||
.set_public_id(String::from(public_id)) | ||
.set_overwrite(true); | ||
let res = cloudinary | ||
.upload_image(Source::Url(image_url.try_into().unwrap()), &options) | ||
.await | ||
.unwrap(); | ||
|
||
match res { | ||
Success(img) => assert_eq!(img.public_id, public_id), | ||
Error(err) => panic!("{}", err.error.message), | ||
} | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_image_upload_from_path() { | ||
dotenv().ok(); | ||
let api_secret = var("CLOUDINARY_API_SECRET").expect("enviroment variables not set"); | ||
let api_key = var("CLOUDINARY_API_KEY").expect("enviroment variables not set"); | ||
let cloud_name = var("CLOUDINARY_CLOUD_NAME").expect("enviroment variables not set"); | ||
|
||
let cloudinary = Cloudinary::new(api_key, cloud_name, api_secret); | ||
let image_path = "./assets/1x1.png"; | ||
let public_id = "image_upload_from_path"; | ||
|
||
let options = UploadOptions::new() | ||
.set_public_id(String::from(public_id)) | ||
.set_overwrite(true); | ||
let res = cloudinary | ||
.upload_image(Source::Path(image_path.try_into().unwrap()), &options) | ||
.await | ||
.unwrap(); | ||
|
||
match res { | ||
Success(img) => assert_eq!(img.public_id, public_id), | ||
Error(err) => panic!("{}", err.error.message), | ||
} | ||
} |