尝试使用载波和s3上传照片时出错

时间:2017-09-23 12:31:46

标签: ruby-on-rails ruby amazon-s3 carrierwave

这是我在终端中的错误,

Excon::Error::Socket (getaddrinfo: nodename nor servname provided, or not known (SocketError)):

app/controllers/properties_controller.rb:15:in `create'

这是视图页面

getaddrinfo: nodename nor servname provided, or not known (SocketError)

这是我的雾文件,

CarrierWave.configure do |config|
  config.fog_provider = 'fog/aws'                        # required
  config.fog_credentials = {
provider:              'AWS',                        # required
aws_access_key_id:     ENV['AWS_APP_KEY'],                        # required
aws_secret_access_key: ENV['AWS_APP_SECRET'],                        # required
region:                'us-east-1',                  # optional, defaults to 'us-east-1'
host:                  's3.example.com',             # optional, defaults to nil
endpoint:              's3-external-1.amazonaws.com' # optional, defaults to nil
}
config.fog_directory  = ENV['AWS_BUCKET_NAME']                          # required
config.fog_public     = false                                        # optional, defaults to true
config.fog_attributes = { cache_control: "public, max-age=#{365.day.to_i}" } # optional, defaults to {}
end

任何帮助将不胜感激

  def create
@property = Property.new(property_params)

  if @property.save
    redirect_to root_path
  else
    render 'new'
  end
end


  private
  def property_params
if params[:property][:amenities].class == Array
  params[:property][:amenities] = params[:property][:amenities].join(",")
end
params.require(:property).permit(:property_name, :city, :ppm, :images, :user_id, :amenities, {property_images: []})

end

它希望我添加更多细节,所以我尝试更改区域等...

我也需要'excon'

2 个答案:

答案 0 :(得分:1)

问题在于您的配置端点,

您不需要主持人入境。 我修改了端点以使用标准的s3 url。

CarrierWave.configure do |config|
  config.fog_provider = 'fog/aws'                        # required
  config.fog_credentials = {
provider:              'AWS',                        # required
aws_access_key_id:     ENV['AWS_APP_KEY'],                        # required
aws_secret_access_key: ENV['AWS_APP_SECRET'],                        # required
region:                'us-east-1',                  # optional, defaults to 'us-east-1'
endpoint:              's3.amazonaws.com' # optional, defaults to nil
}
config.fog_directory  = ENV['AWS_BUCKET_NAME']                          # required
config.fog_public     = false                                        # optional, defaults to true
config.fog_attributes = { cache_control: "public, max-age=#{365.day.to_i}" } # optional, defaults to {}
end

参考文件:

https://github.com/carrierwaveuploader/carrierwave/wiki/How-to:-Use-minio-with-Carrierwave

https://github.com/carrierwaveuploader/carrierwave/issues/1802

希望它有所帮助。

答案 1 :(得分:1)

将CarrierWave配置选项主机更改为指向's3.amazonaws.com'而不是's3.example.com'