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