使用carrierwave将图像上传到s3并使用雾黑色uri

时间:2013-03-30 10:17:16

标签: ruby-on-rails carrierwave fog

您好我正在尝试使用雾和载波在s3上传一些图像。在我在公共文件夹中执行此操作之前,我想将其放在存储桶中。当我试图上传新图片时,我得到: URI::InvalidURIError错误URI中的EventsController create(不是URI?)

我做了一些研究,可能来自名称中的“+”符号,但我没有任何“+” 这是我的参数请求:

> {"utf8"=>"✓",
 "authenticity_token"=>"ms48hFw8dTALEe543dPS0ywIdKynYvuAHMjiry7kghQ=",
 "event"=>{"titre"=>"test des image avec S3",
 "dday(1i)"=>"2013",
 "dday(2i)"=>"3",
 "dday(3i)"=>"30",
 "lieux"=>"maison",
 "commentaire"=>"aucune",
 "pictures_attributes"=>{"0"=>{"name"=>"test",
 "image"=>#<ActionDispatch::Http::UploadedFile:0xa35a14c @original_filename="image.jpg",
 @content_type="image/jpeg",
 @headers="Content-Disposition: form-data; name=\"event[pictures_attributes][0][image]\"; filename=\"image.jpg\"\r\nContent-Type: image/jpeg\r\n",
 @tempfile=#<File:/tmp/RackMultipart20130330-26465-11z9gsf>>}}},
 "commit"=>"Ajouter"}

我已按照https://github.com/jnicklas/carrierwave的说明进行操作 这是一些代码

CarrierWave.configure do |config|
    config.fog_credentials = {
        :provider               => 'AWS',                        # required
        :aws_access_key_id      => 'xxx',                        # required
        :aws_secret_access_key  => 'xxx',                        # required
        :region                 => 'eu-west-1',                  # optional, defaults to 'us-east-1'
        :host                   => 'xxx.com',             # optional, defaults to nil
        :endpoint               => '' # optional, defaults to nil
    }
    config.fog_directory  = 'socialmausoleum'                     # required
    config.fog_public     = true                                  # optional, defaults to true
    config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}  # optional, defaults to {}
end

和我的上传者:

class ImageUploader < CarrierWave::Uploader::Base

  # Include RMagick or MiniMagick support:
  # include CarrierWave::RMagick
  # include CarrierWave::MiniMagick

  # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
  # include Sprockets::Helpers::RailsHelper
  # include Sprockets::Helpers::IsolatedHelper

  # Choose what kind of storage to use for this uploader:
  storage :file
  storage :fog

  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

感谢您的回答。

1 个答案:

答案 0 :(得分:1)

在黑暗中拍摄

:endpoint               => '' # optional, defaults to nil

nil≠''

所以,只需删除整个林,看看会发生什么。我认为正在发生的事情是它试图将一个空字符串追加到以“+”结尾但后面没有任何内容的结尾处。

编辑:

来自他们的文档

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',                        # required
    :aws_access_key_id      => 'xxx',                        # required
    :aws_secret_access_key  => 'yyy',                        # required
    :region                 => 'eu-west-1',                  # optional, defaults to 'us-east-1'
    :host                   => 's3.example.com',             # optional, defaults to nil
    :endpoint               => 'https://s3.example.com:8080' # optional, defaults to nil
  }
  config.fog_directory  = 'name_of_directory'                     # required
  config.fog_public     = false                                   # optional, defaults to true
  config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}  # optional, defaults to {}
end

在您的情况下,您将需要我认为匹配的区域,但我认为您不需要主机或端点。