title: Carrierwave & Amazon S3 file downloading/uploading
body: <p>I have a rails 3 app with an UploadsUploader and a Resource model on which this is mounted. I recently switched to using s3 storage and this has broken my ability to download files using the send_to method. I can enable downloading using the redirect_to method which is just forwarding the user to an authenticated s3 url. I need to authenticate file downloads and I want the url to be <a href="http://mydomainname.com/the_file_path" rel="noreferrer">http://mydomainname.com/the_file_path</a> or <a href="http://mydomainname.com/controller_action_name/id_of_resource" rel="noreferrer">http://mydomainname.com/controller_action_name/id_of_resource</a> so I am assuming I need to use send_to, but is there a way of doing that using the redirect_to method? My current code follows. Resources_controller.rb</p>
  
  <pre><code>def download
    resource = Resource.find(params[:id])
      if resource.shared_items.find_by_shared_with_id(current_user) or resource.user_id == current_user.id
          filename = resource.upload_identifier
          send_file "#{Rails.root}/my_bucket_name_here/uploads/#{filename}"
      else
          flash[:notice] = "You don't have permission to access this file."
          redirect_to resources_path
      end
  end
  </code></pre>
  
  <p>carrierwave.rb initializer:</p>
  
  <pre><code>CarrierWave.configure do |config|
    config.fog_credentials = {
      :provider               =&gt; 'AWS',       # required
      :aws_access_key_id      =&gt; 'xxxx',       # copied off the aws site
      :aws_secret_access_key  =&gt; 'xxxx',       # 
    }
  
    config.fog_directory  = 'my_bucket_name_here'                     # required
    config.fog_host       = 'https://localhost:3000'            # optional, defaults to nil
    config.fog_public     = false                                   # optional, defaults to true
    config.fog_attributes = {'Cache-Control'=&gt;'max-age=315576000'}  # optional, defaults to {}
  end
  </code></pre>
  
  <p>upload_uploader.rb</p>
  
  <pre><code>class UploadUploader &lt; CarrierWave::Uploader::Base
    storage :fog
  
    def store_dir
      "uploads"
    end
  end
  </code></pre>
  
  <p>All of this throws the error:</p>
  
  <blockquote>
    <p>Cannot read file
    /home/tom/Documents/ruby/rails/circlshare/My_bucket_name_here/uploads/Picture0024.jpg</p>
  </blockquote>
  
  <p>I have tried reading up about carrierwave, fog, send_to and all of that but everything I have tried hasn't been fruitful as yet. Uploading is working fine and I can see the files in s3 bucket. Using re_direct would be great as the file wouldn't pass through my server. Any help appreciated. Thanks.</p>