1

嗨,我正在尝试使用雾和载波在 s3 上上传一些图像。在我在我的公共文件夹中做之前,我想把它放在一个桶上。当我尝试上传新图片时,我得到: URI::InvalidURIErrorEventsController create错误的 URI 中(不是 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

谢谢你的回答。

4

1 回答 1

1

在黑暗中拍摄

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

无≠''

所以只需删除整个 lin 看看会发生什么。我认为正在发生的是它试图将一个空字符串附加到以“+”结尾的内容的末尾,然后什么都没有。

编辑:

从他们的文档

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

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

于 2013-03-31T20:13:25.440 回答