如何从客户端 JavaScript 从 cloudinary 获取我的图像列表

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

本文关键字:我的 图像 获取 列表 JavaScript 客户端 cloudinary      更新时间:2023-09-26

使用云 API,我可以通过GET以下 URL 来获取图像列表:

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

但是,从客户端 JavaScript 使用它会暴露我帐户的 API 密钥和机密。

似乎可以在不暴露我帐户凭据的情况下获取图像列表。

我看过Cloudinary AngularJS客户端,它有一个示例项目,可以在帐户中实现照片的幻灯片。 据我所知,该项目使用以下行来获取云帐户中的照片列表

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

但是我无法接到这个电话来回复任何东西。

Cloudinary JQuery 文档没有描述 $.cloudinary.url() 的语法;我找到的唯一资源是在 Cloudinary JQuery Github 页面上,其中指出

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

什么是public_id? 有哪些options

浏览所有资源确实需要使用受保护的管理员 API。这确实需要使用您的api_secret而您的不应该在您的客户端代码中显示。但是,Cloudinary 支持返回共享某个标签的所有图像/原始文件的列表。响应是一个 JSON 代码段,该代码段会在 CDN 上自动更新并缓存 1 小时。

cloudinary.url API 生成指定参数的 URL。因此,使用时:

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

这将生成一个云 URL,如下所示:

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

此网址返回您帐号中共享">我的相册"标签的所有资源的 JSON。

阅读文档链接 http://support.cloudinary.com/hc/en-us/articles/203189031-How-to-retrieve-a-list-of-all-resources-sharing-the-same-tag-

我确实取消选中了"安全>受限图像类型"下的"资源列表"。然后我可以看到图像列表。