我使用rails 3用云和载波将照片上传到服务器。
class NutsController < ApplicationController
include UsersHelper
include NutsHelper
def index
if current_user
@user = User.find(session[:user_id])
@nuts = Nut.all
else
redirect_to :root
end
end
def new
# current_user
end
def show
end
def create
if params[:file].present?
@upload = Cloudinary::Uploader.upload(params[:file])
@picture = @upload["secure_url"]
end
@nut = Nut.new(url: [@picture])
if @nut.save
redirect_to user_path(current_user)
end
end
end<
<%= cloudinary_js_config %>
<h1>Create a Nushell</h1>
<%= form_for :nut, url: nuts_path do |f| %>
<%= cl_image_upload_tag(:image_id) %>
<%= f.submit "Nut it Up!"%>
<% end %>class PictureUploader < CarrierWave::Uploader::Base
include Cloudinary::CarrierWave
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end我的文件名为Yellow_Happy.jpg。当我打印出params:file时,它返回‘黄_幸福. out’。要上传到cloudinary,我需要我的文件的整个路径,即用户/学徒/桌面/黄_幸福. the。有人知道如何指定我文件的整个路径吗?
发布于 2014-07-21 06:04:02
如果您查看您的Uploader代码,您已经指定了storage :file,它基本上告诉载波在您的应用程序中上传图像,而store_dir函数则告诉您在哪里上传图像。您甚至可以在app/public/uploads中检查它。有关更多详细信息,请查看carrierwave documentation
如果您查看cloudinary documentation,您只需要在上传器中包含Cloudinary::载波(除非您使用缩略图或其他载波功能)。上传者应该是这样的:
class PictureUploader < CarrierWave::Uploader::Base
include Cloudinary::CarrierWave
#storage :file #You don't need it
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
endhttps://stackoverflow.com/questions/24853262
复制相似问题