title: Carrierwave upload and access file on S3
body: <p>I am struggling to access files on S3 with Carrierwave.</p>
  
  <p>In my uploader file doc_uploader.rb I have the following code</p>
  
  <pre><code>storage :file
  def store_dir
  "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
  </code></pre>
  
  <p>to uplooad "doc" model defined as follow</p>
  
  <pre><code>class Doc &lt; ActiveRecord::Base
  belongs_to :user
  mount_uploader :doc, DocUploader
  end
  </code></pre>
  
  <p>To access the uploaded file I have the following line of code in a controller</p>
  
  <pre><code>@doc = current_user.docs.order("created_at").last #last file uploaded by user
  io = open("#{Rails.root}/public" + @doc.doc.url)
  </code></pre>
  
  <p>Everything works perfectly locally. Now I want to move my file to S3 in the uploader I use fog and replace</p>
  
  <pre><code>storage :file
  </code></pre>
  
  <p>by </p>
  
  <pre><code>storage :fog
  </code></pre>
  
  <p>I adjust my config file carrierwave.rb and <strong>uploading works perfectly</strong>. However, to access the file I try to use </p>
  
  <pre><code>@doc = current_user.docs.order("created_at").last
  io = open("#{@doc.doc.url}")
  </code></pre>
  
  <p>and I get the following error</p>
  
  <pre><code>No such file or directory @ rb_sysopen - /uploads/doc/doc/11/the_uploaded_file.pdf
  </code></pre>
  
  <p>Could anyone give me the right syntax to access the file on S3 please? Thanks.</p>