【问题标题】:Error trying to upload a photo using carrier wave and s3尝试使用载波和 s3 上传照片时出错
【发布时间】:2018-03-04 21:52:22
【问题描述】:

这是我在终端的错误,

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'

【问题讨论】:

  • 嗨,Dave,您能从您的属性控制器中提供create 方法吗?
  • 刚刚添加。谢谢
  • 我认为您需要将 CarrierWave 配置选项 host 更改为指向 's3.amazonaws.com' 而不是 's3.example.com'

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


【解决方案1】:

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

【讨论】:

  • 太好了,似乎已经解决了这个错误,我现在只剩下这个:坏 URI(不是 URI?):://(my-bucket-name).s3.amazonaws.com :
【解决方案2】:

问题在于您的配置端点,

您不需要主机条目。 我已修改端点以使用标准 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

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2017-07-22
    • 2014-06-12
    • 2012-03-16
    • 1970-01-01
    • 1970-01-01
    • 2019-05-08
    • 2013-07-21
    • 1970-01-01
    • 2023-03-05
    相关资源
    最近更新 更多