首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将照片上传到网站上需要绝对路径

将照片上传到网站上需要绝对路径
EN

Stack Overflow用户
提问于 2014-07-20 17:50:46
回答 1查看 399关注 0票数 1

我使用rails 3用云和载波将照片上传到服务器。

代码语言:javascript
复制
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

<

代码语言:javascript
复制
<%= 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 %>

代码语言:javascript
复制
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。有人知道如何指定我文件的整个路径吗?

EN

回答 1

Stack Overflow用户

发布于 2014-07-21 06:04:02

如果您查看您的Uploader代码,您已经指定了storage :file,它基本上告诉载波在您的应用程序中上传图像,而store_dir函数则告诉您在哪里上传图像。您甚至可以在app/public/uploads中检查它。有关更多详细信息,请查看carrierwave documentation

如果您查看cloudinary documentation,您只需要在上传器中包含Cloudinary::载波(除非您使用缩略图或其他载波功能)。上传者应该是这样的:

代码语言:javascript
复制
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
end
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24853262

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档