Conversation
Lurk
left a comment
There was a problem hiding this comment.
Thank you for your contribution. Please check out the comments.
src/lib.rs
Outdated
| /// "cloud_name".to_string(), | ||
| /// "api_secret".to_string() | ||
| /// ); | ||
| /// let options = UploadOptions::new().set_public_id("app_data.sql".to_string()); |
There was a problem hiding this comment.
I actually did plan on saving some sql files to the cloud 🙂
There was a problem hiding this comment.
Yeah, but you're passing it to a cloudinary.upload_image
There was a problem hiding this comment.
Oh sorry about that. I've fixed the examples.
| pub format: String, | ||
| pub width: Option<usize>, | ||
| pub height: Option<usize>, | ||
| pub format: Option<String>, |
There was a problem hiding this comment.
Do you know if it is documented somewhere?
There was a problem hiding this comment.
Yeah files like audio files, text files etc don't have width and height. There's a an example here
There was a problem hiding this comment.
Instead of optional width params, I would like a more strict result type. If we upload an image, we know the result should have width, height, and format. And if we upload audio, it does not.
| "https://api.cloudinary.com/v1_1/{}/{}/upload", | ||
| self.cloud_name, | ||
| options | ||
| .get_resource_type() |
There was a problem hiding this comment.
I don't think upload options can be 100% shared between images, videos, and sound. For example, "faces" are relevant for images only.
There was a problem hiding this comment.
From my understanding of the docs, the upload parameters are somewhat general. Perhaps cloudinary's api will accept the valid options based on the resource_type or the specific endpoint called, I'm nor really sure
| options: &UploadOptions<'_>, | ||
| ) -> Result<UploadResult> { | ||
| let new_opts = options.clone(); | ||
| let updated_options = new_opts.set_resource_type(ResourceTypes::Image); |
There was a problem hiding this comment.
If options already contain resource type, we will silently overwrite it, which is a potential bug in a client application. We can catch it on compile time.
There was a problem hiding this comment.
Yeah, I thought since the person is using the upload_image method, then the resource_type will have to be an image whether they set it or not
There was a problem hiding this comment.
We can let them know that the overwrite will happen in the docs
There was a problem hiding this comment.
How I image this API:
cloudinary.upload(Options::Image(...image_specific_options...))->UploadResultEnum;
cloudinary.upload_image(...image_specific_options...)->...image_specific_result
cloudinary.upload_audio(...audio_specific_options...)->...audio_specific_resultThere was a problem hiding this comment.
Yeah, I get this. So I've used the official Python SDK, and it doesn't have an upload_audio method, it just has an upload_image and an upload method that can still be used to upload images.
There was a problem hiding this comment.
We'll probably need to determine the return type based on the values that are passed in as options. Hmmm.
There was a problem hiding this comment.
I'm currently participating in a Hackathon that's ending Wednesday. Please I'll tackle this after.
| let env_vars = load_env(); | ||
| let cloudinary = Cloudinary::new(env_vars.api_key, env_vars.cloud_name, env_vars.api_secret); | ||
|
|
||
| let audio_url = "https://commons.wikimedia.org/wiki/File:Panama_National_Anthem.ogg"; |
There was a problem hiding this comment.
I would like to have a small file locally.
There was a problem hiding this comment.
Yeah that's fine, I just thought that for the test to run smoothly for everyone that clones the project, a url would work better.
There was a problem hiding this comment.
Unfortunately, URLs tend to change at the most inconvenient moment. We have https://github.com/Lurk/cloudinary_rs/tree/main/assets in the repo.
src/lib.rs
Outdated
| /// "cloud_name".to_string(), | ||
| /// "api_secret".to_string() | ||
| /// ); | ||
| /// let options = UploadOptions::new().set_public_id("app_data.sql".to_string()); |
There was a problem hiding this comment.
Yeah, but you're passing it to a cloudinary.upload_image
| pub format: String, | ||
| pub width: Option<usize>, | ||
| pub height: Option<usize>, | ||
| pub format: Option<String>, |
There was a problem hiding this comment.
Instead of optional width params, I would like a more strict result type. If we upload an image, we know the result should have width, height, and format. And if we upload audio, it does not.
| options: &UploadOptions<'_>, | ||
| ) -> Result<UploadResult> { | ||
| let new_opts = options.clone(); | ||
| let updated_options = new_opts.set_resource_type(ResourceTypes::Image); |
There was a problem hiding this comment.
How I image this API:
cloudinary.upload(Options::Image(...image_specific_options...))->UploadResultEnum;
cloudinary.upload_image(...image_specific_options...)->...image_specific_result
cloudinary.upload_audio(...audio_specific_options...)->...audio_specific_result| let env_vars = load_env(); | ||
| let cloudinary = Cloudinary::new(env_vars.api_key, env_vars.cloud_name, env_vars.api_secret); | ||
|
|
||
| let audio_url = "https://commons.wikimedia.org/wiki/File:Panama_National_Anthem.ogg"; |
There was a problem hiding this comment.
Unfortunately, URLs tend to change at the most inconvenient moment. We have https://github.com/Lurk/cloudinary_rs/tree/main/assets in the repo.
So I added the upload method to upload other kind of files like video and audio.
Sorry I didn't follow up on my last pull request, I was in school.