上传图像Cloudinary。我 得到它通过使用CarrierWave本地保存的图像,我知道Cloudinary和 CarrierWave互相发挥很好,但我已经竭尽所能,并没有骰子。无法从西纳特拉
我跟着文档,但他们都非常的Rails为中心。该死的你Rails!
# Model - User.rb
class ImageUploader < CarrierWave::Uploader::Base
include Cloudinary::CarrierWave
process convert: 'png'
version :face do
cloudinary_transformation gravity: :face
end
end
class User
include DataMapper::Resource
attr_accessor :image
property.............
mount_uploader :image, ImageUploader
end
# Config - app.rb
require 'carrierwave/datamapper'
require 'cloudinary'
# DataMapper code ...
# Some routes ...
post '/add' do
user = user.create(name: params[:name])
Cloudinary::Uploader.upload(params[:image], api_key: 'API_KEY', api_secret: 'API_SECRET', cloud_name: 'CLOUD_NAME')
# View (haml)
%head
%script{src: "//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"}
%script{src: "js/cloudinary_js/jquery.ui.widget.js"}
%script{src: "js/cloudinary_js/jquery.iframe-transport.js"}
%script{src: "js/cloudinary_js/jquery.fileupload.js"}
%script{src: "js/cloudinary_js/jquery.cloudinary.js"}
# snip snip ...
%form{action: "/add", method: "POST", enctype: "multipart/form-data"}
%input{type: "file", name: "image"}
%button Submit
试图提交表单时,我得到的错误是:
TypeError at /add
no implicit conversion of Hash into String
线它给了我,导致该错误是在POST方法Cloudinary上传线。
这里是我的PARAMS [:图片]哈希
{:filename=>"batman_robin.jpg", :type=>"image/jpeg", :name=>"image", :tempfile=>#<Tempfile:/var/folders/rv/2w8gpstn4hb2lb__27n27ksh0000gn/T/RackMultipart20131223-36484-tgmaba>, :head=>"Content-Disposition: form-data; name=\"image\"; filename=\"batman_robin.jpg\"\r\nContent-Type: image/jpeg\r\n"}
在文档它提到一个文件签名,然后指出CarrierWave处理此。我认为我的问题在于上传表单。
我要去哪里错了呢?任何人都知道'cl_image_upload_tag'会产生什么,以及我需要将Cloudinary的“特殊属性”添加到我的文件上传标签中?
UPDATE:所以我想,我可以实际上只是直接传递图像,像这样:
Cloudinary::Uploader.upload(params[:image][:filename] ...
但是现在说
No such file or directory - batman_robin.jpg
这是奇怪的。我在那里硬编码了一个URL并将其上传到Cloudinary。有任何想法吗?此外,任何关于Cloudinary jQuery上传的想法?