Can you set the public_id when uploading multiple images?
I understand how to set the public_id of single image being uploaded. (I'm using PHP and jQuery.) If I allow multiple files to be uploaded at once, is there a way to set the public_ids as they are uploaded? I'd still like to have readable names, and perhaps add a sequence number or random characters to each name.
Thanks,
Doug
-
Hi Doug,
You can choose to keep the original file's name, by setting the
use_filenameparameter totruewhile uploading. This way the public ID is automatically using the original name of the uploaded file (normalizing the name to avoid non URL friendly characters and adding a random suffix to promise uniqueness). You can see this behavior by uploading images using the Media Library UI of our Management Console.Here's an example (in PHP) of uploading a file, while keeping its file name:
\Cloudinary\Uploader::upload('sample.jpg', array("use_filename" => TRUE));
Here'rs an example using
cl_image_upload_tag, including multiple uploads:<?php echo cl_image_upload_tag("image_id", array("html" => array("multiple" => TRUE ), "use_filename" => TRUE)); ?>
This will create URLs for your files similar to this:
http://res.cloudinary.com/<cloud\_name>/image/upload/v1377681437/sample_mzzi4k.jpg
In addition, your images' public ID can contain one or more folders by adding the
folderparameter to the upload call.For more information:
http://support.cloudinary.com/entries/25760887-Can-I-upload-files-to-a-folder-while-keeping-their-original-file-names-0 -
Thanks! The folder approach will help a lot, actually--I wasn't aware of that possibility.
0
Post is closed for comments.
Comments
2 comments