我知道我的文件存储在AWS中,但是当我尝试获取它时,会收到错误消息:Errno :: ENOENT(没有文件或目录@ rb_sysopen

时间:2018-06-27 23:46:30

标签: amazon-s3 paperclip

我正在运行一个heroku应用程序,并且正在使用AWS S3存储我的文件。我看到我的照片正在上传:

my bucket

但是当我尝试获取照片时,出现错误消息:

  

Errno :: ENOENT(没有这样的文件或目录@ rb_sysopen-   //diariocapilar-aws-data.s3.us-east-1.amazonaws.com/photos/products/18/IMG-20180627-WA0007.jpg?1530142589)

这是我的回形针设置:

config / initializers / paperclip.rb:

Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'
Paperclip::Attachment.default_options[:s3_host_name] = 's3.us-east-1.amazonaws.com'

production.rb:

  config.paperclip_defaults = {
    storage: :s3,
    s3_credentials: {
      bucket: ENV.fetch('S3_BUCKET_NAME'),
      access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
      secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY')
    },
      s3_region: ENV.fetch('AWS_REGION')
  }

config / application.yml

   S3_BUCKET_NAME: "diariocapilar-aws-data"
    AWS_ACCESS_KEY_ID: "xxxxxxxxxxx"
    AWS_SECRET_ACCESS_KEY: "xxxxxxxxxx"
    S3_REGION: "us-east-1"
    S3_HOST_NAME: "s3.us-east-1.amazonaws.com"
    AWS_REGION: "us-east-1"

config / s3.yml

   development:
      bucket: diariocapilar-aws-data
      access_key_id: xxxxxx
      secret_access_key: xxxxxx
    test:
      bucket: diariocapilar-aws-data
      access_key_id: xxxxxx
      secret_access_key: xxxxxx
    production:
      bucket: diariocapilar-aws-data
      access_key_id: xxxxxx
      secret_access_key: xxxxxx

最后是我的产品型号:

class Product < ApplicationRecord

  attr_accessor :photo

  has_attached_file :photo, styles: { medium: "300x300>", thumb: "150x150>" },
    :storage => :s3,
    :s3_credentials => "#{Rails.root}/config/s3.yml",
    :s3_permissions => :private,
    :path => "photos/products/:id/:filename"

我正在尝试在控制器中执行此操作的图像:

  def photo
    @product = Product.find(params[:id])
    data = open("#{@product.photo.url}") 
    send_data data.read, :type => data.content_type, :x_sendfile => true
  end

我想了解为什么会这样。我正在努力使它整天工作

0 个答案:

没有答案