title: Errno::ENOENT - No such file or directory @ rb_sysopen in Rails
body: <p>I am working on maintenance project which is migrated from Rails 3.2.13 to Rails 4.2.
  Here there is a scenario where when I upload a photo / indicator, it will be stored in AWS.
  But, when I submit the data, I am facing the below error:</p>
  
  <blockquote>
    <p>New RightAws::S3Interface using shared connections mode Opening new
    HTTPS connection to nudge.development.s3.amazonaws.com:443 Opening new
    HTTPS connection to s3.amazonaws.com:443 Completed 500 Internal Server
    Error in 3816ms (ActiveRecord: 14.4ms)
    ** [Airbrake] Notice was not sent due to configuration:            Environment Monitored? false            API key set? true</p>
    
    <p>Errno::ENOENT - No such file or directory @ rb_sysopen -
    /home/myproject/public/photo_screenshots/128.png:<br>
    lib/screenshot.rb:43:in <code>upload'   lib/screenshot.rb:8:in</code>initialize'
    app/controllers/reports_controller.rb:221:in <code>send_report_email'<br>
    actionpack (4.2.6) lib/action_controller/metal/implicit_render.rb:4:in
    </code>send_action'<br>
    .....................................................................................
    .....................................................................................</p>
  </blockquote>
  
  <p>This is my code:</p>
  
  <p>lib/screenshot.rb:</p>
  
  <pre><code>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' =&gt; 'image/png' }) : s3.bucket("nudge.#{Rails.env}", true).put("indicator_screenshots/#{@report_id}.png", File.open(file_name), {}, 'public-read', { 'content-type' =&gt; '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
  </code></pre>
  
  <p>reports_controller:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Please help.</p>