REST API Eager Transformation Conditional Transformation
I'm uploading via the browser using a form and the REST API (as detailed here https://cloudinary.com/documentation/upload_images#manual_signature_generation)
I would like to perform an eager transformation based on the image type - if the file being uploaded is a PDF then convert the first page to a png:
I think I need to do something like:
formData.append("eager", "if_ctx:!<what do I use here>!_eq_!pdf!/f_png/if_end");
But I can't find a conditional image characteristic that uses the image format.
Is this possible and if so what should I use in my eager transformation paramater?
-
Hi,
There isn't a characteristic you can use in conditional transformations that's based on the detected format of the file. As a possible alternative, for multi-page PDFs, you could use the page count in your condition - see "pc" at https://cloudinary.com/documentation/conditional_transformations#specifying_conditions
That said, it's also not possible to set the format in a conditional transformation: https://cloudinary.com/documentation/conditional_transformations#supported_conditional_image_transformation_parameters_and_flags but when delivering you can always specify a file extension JPG or PNG, and add f_auto as a transformation option so a more optimal format will be chosen when delivering the asset, if supported by the user's browser
It may also be worth mentioning that the default behaviour when accessing a PDF as an image and applying transformation parameters to the URL is that the first page is returned, so what you're looking for may already be the default behavior here: https://cloudinary.com/documentation/paged_and_layered_media#deliver_a_selected_pdf_page_as_an_image
Depending on your exact requirements, another option is to change the options you add on the API call in your own code after detecting what type of file you're about to upload - you may have a filename passed by the user or filesystem for example.
Regards,
Stephen0
Post is closed for comments.
Comments
1 comment