阅读背景:

如何从cloudinary和rails中检索图像标题?

来源:互联网 

I'm trying to add a caption below my cloudinary image. On the cloudinary website, I've added my caption under the "edit metadata" field, but I can't figure out how to retrieve it.

我正在尝试在我的云图像下面添加一个标题。在cloudinary网站上,我在“编辑元数据”字段下添加了我的标题,但我无法弄清楚如何检索它。

My controller:

我的控制器:

require 'cloudinary'
results = Cloudinary::Api.resources(:type => :upload)
resources = results["resources"]
@ids = resources.map {|res| res["public_id"]}

My view:

我的看法:

<% @ids.each do |id| %>
  <%= cl_image_tag (id) %>
  **insert caption here**
<% end %>

1 个解决方案

#1


1  

To get the image metadata you've inserted, you'll have to set context to true when running the resources method, like this:

要获取已插入的图像元数据,您必须在运行资源方法时将上下文设置为true,如下所示:

results = Cloudinary::Api.resources(:type => :upload, :context => true)

results = Cloudinary :: Api.resources(:type =>:upload,:context => true)

The above request will also return key-value pairs as in the metadata you've inserted, like this:

上面的请求也将返回您插入的元数据中的键值对,如下所示:

"context"=>{"custom"=>{"caption"=>"flowers"}}

“上下文”=> { “定制”=> { “字幕”=> “花”}}


分享到: