seed cloudinary photos for rails app

醉酒当歌 提交于 2019-12-12 06:56:17

问题


)

I have some cloudinary's photos and I would like to make a seed (in my rails app). I'm using Carrierwave.

In my seed, I try to put the cloudinary's url image :

Course.create! ({
  photo: "fismpnq3zma80dc2ovjt.jpg"
)}

But it's don't work. What can I do ?

If I ask by console :

pry(main)> c = Course.first
....
pry(main)> c.photo

@cache_id=nil,
@file=nil,
@filename=nil,
....
@model=#<Way:0x00007f80e7a3a9c0
photo:nil,
....
@mounted_as=:photo,
@versions=nil>

回答1:


In order to use the create method, the parameters need to be verified (by signature) before the SDK will save them.

For example:

resource_type = "image" 
type = "upload"
version = 1234567890
public_id = "fismpnq3zma80dc2ovjt"
format = "jpg"
signature = Cloudinary::Utils.api_sign_request({:public_id=>public_id, 
:version=>version}, Cloudinary.config.api_secret)
photo = "#{resource_type}/#{type}/v#{version}/#{public_id}.#{format}## 
{signature}"
Course.create!({ photo: photo )}

Please let me know if it works for you.

--Yakir



来源:https://stackoverflow.com/questions/51163036/seed-cloudinary-photos-for-rails-app

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