title: Carrierwave gem Secure File Path Cannot read file error
body: <p>I tried to follow the 'Secure Upload' in carrier wave which is a bit confusing because I have customized the file path and all a bit. When I try to run the app, I get 'Cannot read file' error.</p>
  
  <p>Here's the route :</p>
  
  <pre><code>match "/uploads/tobereviewed/:user.:username.downcase/:basename.:extension", :controller =&gt; "photos", :action =&gt; "uploaded", via: :get
  </code></pre>
  
  <p>The sotre_dir of uploader :</p>
  
  <pre><code>class SubmitUploader &lt; CarrierWave::Uploader::Base
  
  def store_dir
    "uploads/tobereviewed/#{model.user.username.downcase}"
  end
  </code></pre>
  
  <p>carrierwave.rb initializer :</p>
  
  <pre><code>    CarrierWave.configure do |config|
        config.permissions = 0600
        config.directory_permissions = 0700
        config.root = Rails.root
      end
  </code></pre>
  
  <p>Photos controller :</p>
  
  <pre><code>    def uploaded
  
          file = Submit.first
  
          send_file "#{Rails.root}/uploads/tobereviewed/#{file.user.username.downcase}/#{file.id}"
      end
  </code></pre>
  
  <p>The full error log :</p>
  
  <pre><code>Started GET "/uploaded" for 127.0.0.1 at 2014-11-27 18:19:09 +0530
  Processing by PhotosController#uploaded as HTML
    User Load (0.4ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1  ORDER BY "users"."id" ASC LIMIT 1  [["id", 1]]
    Submit Load (2.6ms)  SELECT  "submits".* FROM "submits"  ORDER BY "submits"."id" ASC LIMIT 1
    User Load (2.2ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1  [["id", 1]]
  Sent file /home/pubudu/Projects/istockseller/uploads/tobereviewed/thpubs/36603935 (0.7ms)
  Completed 500 Internal Server Error in 54ms
  
  ActionController::MissingFile - Cannot read file /home/pubudu/Projects/istockseller/uploads/tobereviewed/thpubs/36603935:
    actionpack (4.2.0.beta4) lib/action_controller/metal/data_streaming.rb:68:in `send_file'
    actionpack (4.2.0.beta4) lib/action_controller/metal/instrumentation.rb:49:in `block in send_file'
    activesupport (4.2.0.beta4) lib/active_support/notifications.rb:164:in `block in instrument'
    activesupport (4.2.0.beta4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    activesupport (4.2.0.beta4) lib/active_support/notifications.rb:164:in `instrument'
    actionpack (4.2.0.beta4) lib/action_controller/metal/instrumentation.rb:47:in `send_file'
     () home/pubudu/Projects/istockseller/app/controllers/photos_controller.rb:24:in `uploaded'
    actionpack (4.2.0.beta4) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
    actionpack (4.2.0.beta4) lib/abstract_controller/base.rb:198:in `process_action'
    actionpack (4.2.0.beta4) lib/action_controller/metal/rendering.rb:10:in `process_action'
    actionpack (4.2.0.beta4) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
    activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:117:in `call'
    activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:169:in `block in halting'
    activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
    activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:234:in `block in halting'
    activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:234:in `block in halting'
    activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:169:in `block in halting'
    activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:92:in `_run_callbacks'
    activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
    activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:81:in `run_callbacks'
    actionpack (4.2.0.beta4) lib/abstract_controller/callbacks.rb:19:in `process_action'
    actionpack (4.2.0.beta4) lib/action_controller/metal/rescue.rb:29:in `process_action'
    actionpack (4.2.0.beta4) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
    activesupport (4.2.0.beta4) lib/active_support/notifications.rb:164:in `block in instrument'
    activesupport (4.2.0.beta4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    activesupport (4.2.0.beta4) lib/active_support/notifications.rb:164:in `instrument'
    actionpack (4.2.0.beta4) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
    actionpack (4.2.0.beta4) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
    activerecord (4.2.0.beta4) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
    actionpack (4.2.0.beta4) lib/abstract_controller/base.rb:137:in `process'
    actionview (4.2.0.beta4) lib/action_view/rendering.rb:30:in `process'
    actionpack (4.2.0.beta4) lib/action_controller/metal.rb:195:in `dispatch'
    actionpack (4.2.0.beta4) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
    actionpack (4.2.0.beta4) lib/action_controller/metal.rb:236:in `block in action'
    actionpack (4.2.0.beta4) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
    actionpack (4.2.0.beta4) lib/action_dispatch/routing/route_set.rb:42:in `serve'
    actionpack (4.2.0.beta4) lib/action_dispatch/journey/router.rb:43:in `block in serve'
    actionpack (4.2.0.beta4) lib/action_dispatch/journey/router.rb:30:in `serve'
    actionpack (4.2.0.beta4) lib/action_dispatch/routing/route_set.rb:780:in `call'
    omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
    omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
    omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
    omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
    warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
    warden (1.2.3) lib/warden/manager.rb:34:in `call'
    rack (1.6.0.beta) lib/rack/etag.rb:23:in `call'
    rack (1.6.0.beta) lib/rack/conditionalget.rb:25:in `call'
    rack (1.6.0.beta) lib/rack/head.rb:13:in `call'
    actionpack (4.2.0.beta4) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
    actionpack (4.2.0.beta4) lib/action_dispatch/middleware/flash.rb:257:in `call'
    rack (1.6.0.beta) lib/rack/session/abstract/id.rb:225:in `context'
    rack (1.6.0.beta) lib/rack/session/abstract/id.rb:220:in `call'
    actionpack (4.2.0.beta4) lib/action_dispatch/middleware/cookies.rb:558:in `call'
    activerecord (4.2.0.beta4) lib/active_record/query_cache.rb:36:in `call'
    activerecord (4.2.0.beta4) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
    activerecord (4.2.0.beta4) lib/active_record/migration.rb:378:in `call'
    actionpack (4.2.0.beta4) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
    activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:88:in `_run_callbacks'
    activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
    activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:81:in `run_callbacks'
    actionpack (4.2.0.beta4) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
    actionpack (4.2.0.beta4) lib/action_dispatch/middleware/reloader.rb:73:in `call'
    actionpack (4.2.0.beta4) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
    better_errors (1.1.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
    better_errors (1.1.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
    better_errors (1.1.0) lib/better_errors/middleware.rb:56:in `call'
    web-console (2.0.0.beta4) lib/action_dispatch/debug_exceptions.rb:18:in `middleware_call'
    web-console (2.0.0.beta4) lib/action_dispatch/debug_exceptions.rb:13:in `call'
    actionpack (4.2.0.beta4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
    railties (4.2.0.beta4) lib/rails/rack/logger.rb:38:in `call_app'
    railties (4.2.0.beta4) lib/rails/rack/logger.rb:20:in `block in call'
    activesupport (4.2.0.beta4) lib/active_support/tagged_logging.rb:68:in `block in tagged'
    activesupport (4.2.0.beta4) lib/active_support/tagged_logging.rb:26:in `tagged'
    activesupport (4.2.0.beta4) lib/active_support/tagged_logging.rb:68:in `tagged'
    railties (4.2.0.beta4) lib/rails/rack/logger.rb:20:in `call'
    actionpack (4.2.0.beta4) lib/action_dispatch/middleware/request_id.rb:21:in `call'
    rack (1.6.0.beta) lib/rack/methodoverride.rb:22:in `call'
    rack (1.6.0.beta) lib/rack/runtime.rb:17:in `call'
    activesupport (4.2.0.beta4) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
    rack (1.6.0.beta) lib/rack/lock.rb:17:in `call'
    actionpack (4.2.0.beta4) lib/action_dispatch/middleware/static.rb:113:in `call'
    rack (1.6.0.beta) lib/rack/sendfile.rb:113:in `call'
    railties (4.2.0.beta4) lib/rails/engine.rb:514:in `call'
    railties (4.2.0.beta4) lib/rails/application.rb:161:in `call'
    rack (1.6.0.beta) lib/rack/tempfile_reaper.rb:15:in `call'
    rack (1.6.0.beta) lib/rack/lint.rb:49:in `_call'
    rack (1.6.0.beta) lib/rack/lint.rb:37:in `call'
    rack (1.6.0.beta) lib/rack/showexceptions.rb:24:in `call'
    rack (1.6.0.beta) lib/rack/commonlogger.rb:33:in `call'
    rack (1.6.0.beta) lib/rack/chunked.rb:54:in `call'
    rack (1.6.0.beta) lib/rack/content_length.rb:15:in `call'
    rack (1.6.0.beta) lib/rack/handler/webrick.rb:89:in `service'
     () home/pubudu/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
     () home/pubudu/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
     () home/pubudu/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
  
  127.0.0.1 - - [27/Nov/2014:18:19:09 +0530] "GET /uploaded HTTP/1.1" 500 - 0.0743
  </code></pre>
  
  <p>Update :</p>
  
  <p>I set the correct file path like this :</p>
  
  <pre><code>send_file "#{file.filename.file}"
  </code></pre>
  
  <p>But then it gives this error :</p>
  
  <pre><code>Cannot read file #&lt;CarrierWave::SanitizedFile:0x007f570c2b9e58&gt;
  </code></pre>
  
  <p><strong>Is my routes correct?</strong></p>