Skip to content

Comments

add general upload method#18

Open
McEazy2700 wants to merge 3 commits intoLurk:mainfrom
McEazy2700:master
Open

add general upload method#18
McEazy2700 wants to merge 3 commits intoLurk:mainfrom
McEazy2700:master

Conversation

@McEazy2700
Copy link

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.

Copy link
Owner

@Lurk Lurk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use sane examples.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually did plan on saving some sql files to the cloud 🙂

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but you're passing it to a cloudinary.upload_image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry about that. I've fixed the examples.

pub format: String,
pub width: Option<usize>,
pub height: Option<usize>,
pub format: Option<String>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if it is documented somewhere?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah files like audio files, text files etc don't have width and height. There's a an example here

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Owner

@Lurk Lurk Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think upload options can be 100% shared between images, videos, and sound. For example, "faces" are relevant for images only.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can let them know that the overwrite will happen in the docs

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll probably need to determine the return type based on the values that are passed in as options. Hmmm.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to have a small file locally.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, URLs tend to change at the most inconvenient moment. We have https://github.com/Lurk/cloudinary_rs/tree/main/assets in the repo.

@Lurk Lurk mentioned this pull request Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants