How do I get a list of my images from cloudinary from client-side JavaScript?

二次信任 提交于 2019-11-28 07:54:44

问题


Using the cloudinary API I can get a list of images by GETting the following URL:

https://API_KEY:API_SECRET@api.cloudinary.com/v1_1/CLOUD_NAME/resources/image/upload

However, using this from client-side JavaScript would expose my account's API key and secret.

It seems like getting a list of images should be possible without exposing my account's credentials.

I've looked at the Cloudinary AngularJS client, which has a sample project that implements a slideshow of photos in an account. From what I can tell, this project uses the following line to get a list of photos in the cloudinary account

var url = $.cloudinary.url('myphotoalbum', {format: 'json', type: 'list'});

But I can't get this call to return anything.

The cloudinary JQuery documentation does not describe the syntax for $.cloudinary.url(); the only resource I've found is on the Cloudinary JQuery Github Page, which states that

$.cloudinary.url(public_id, options) // Returns a cloudinary URL based on your on your configuration and the given options.

What is public_id? What are the options?


回答1:


Browsing through all of your resources indeed require using the secured Admin API. This indeed requires using your api_secret which should not be revealed in your client-side code. However, Cloudinary supports returning a list of all images/raw-files sharing a certain tag. The response is a JSON snippet which is automatically updated and cached for 1 hour at the CDN.

The cloudinary.url API generates a URL of the specified parameters. So when using:

var url = $.cloudinary.url('myphotoalbum', {format: 'json', type: 'list'});

this generates a Cloudinary URL, something like the following:

http://res.cloudinary.com/<your_cloud_name>/image/list/myphotoalbum.json

This URL returns a JSON of all resources in your account sharing the 'myphotoalbum' tag.




回答2:


Read documentation link http://support.cloudinary.com/hc/en-us/articles/203189031-How-to-retrieve-a-list-of-all-resources-sharing-the-same-tag-

I did uncheck the 'Resource list' under "Security > Restricted image types". Then I could able to see the image list.



来源:https://stackoverflow.com/questions/24431943/how-do-i-get-a-list-of-my-images-from-cloudinary-from-client-side-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!