Errno :: ENOENT - 在Rails中没有这样的文件或目录@ rb_sysopen

时间:2016-08-29 09:24:30

标签: ruby-on-rails amazon-s3

我正在研究从Rails 3.2.13迁移到Rails 4.2的维护项目。 这里有一个场景,当我上传照片/指示器时,它将存储在AWS中。 但是,当我提交数据时,我面临以下错误:

  

New RightAws :: S3Interface使用共享连接模式打开新的   HTTPS连接到nudge.development.s3.amazonaws.com:443打开新的   与s3.amazonaws.com的HTTPS连接:443已完成500内部服务器   错误3816ms(ActiveRecord:14.4ms)   ** [Airbrake]由于配置未发送通知:环境监控?错误的API密钥集?真

     

Errno :: ENOENT - 没有这样的文件或目录@ rb_sysopen -   /home/myproject/public/photo_screenshots/128.png:
  lib / screenshot.rb:43:in upload' lib/screenshot.rb:8:in initialize'   app / controllers / reports_controller.rb:221:在send_report_email'
actionpack (4.2.6) lib/action_controller/metal/implicit_render.rb:4:in
send_action'中   .................................................. ...................................   .................................................. ...................................

这是我的代码:

LIB / screenshot.rb:

class Screenshot
  attr_reader :user_id, :report_id, :type

  def initialize(user_id, report_id, type)
      @user_id, @report_id, @type = user_id, report_id, type
      capture
      resize(500, 686) if @type == 'report_screenshots'
      upload    # this is line no 8 which is showing error
      delete_local_copy
  end


  def upload
    file_name = Rails.root.join("public/#{@type}/#{@report_id}.png")
    s3config = YAML.load_file(Rails.root.join('config', 's3.yml'))[Rails.env]
    s3 = RightAws::S3.new(s3config["access_key_id"], s3config["secret_access_key"])
    @type == 'report_screenshots' ? s3.bucket("nudge.#{Rails.env}", true).put("#{@type}/#{@report_id}.png", File.open(file_name), {}, 'public-read', { 'content-type' => 'image/png' }) : s3.bucket("nudge.#{Rails.env}", true).put("indicator_screenshots/#{@report_id}.png", File.open(file_name), {}, 'public-read', { 'content-type' => 'image/png' }) # this is line no 43 which is showing error
    report = Report.find(@report_id)
    @type == 'report_screenshots' ? report.update_attribute(:report_screenshot_at, Time.now) : report.update_attribute(:indicator_screenshot_at, Time.now)
  end

  ..................................................

end

reports_controller:

def send_report_email
   if @report.photos.empty?
      Rails.env.development? ? Screenshot.new(@user.id, @report.id, Rails.application.config.custom.indicator_screenshots) :             Screenshot.delay.new(@user.id, @report.id, Rails.application.config.custom.indicator_screenshot_bucket)
    else
      Rails.env.development? ? Screenshot.new(@user.id, @report.id, "photo_screenshots") : Screenshot.delay.new(@user.id, @report.id, "photo_screenshots")
    end
end

请帮忙。

0 个答案:

没有答案