ruby on rails - Carrierwave gem Secure File Path Cannot read file error -


i tried follow 'secure upload' in carrier wave bit confusing because have customized file path , bit. when try run app, 'cannot read file' error.

here's route :

match "/uploads/tobereviewed/:user.:username.downcase/:basename.:extension", :controller => "photos", :action => "uploaded", via: :get 

the sotre_dir of uploader :

class submituploader < carrierwave::uploader::base  def store_dir   "uploads/tobereviewed/#{model.user.username.downcase}" end 

carrierwave.rb initializer :

    carrierwave.configure |config|       config.permissions = 0600       config.directory_permissions = 0700       config.root = rails.root     end 

photos controller :

    def uploaded          file = submit.first          send_file "#{rails.root}/uploads/tobereviewed/#{file.user.username.downcase}/#{file.id}"     end 

the full error log :

started "/uploaded" 127.0.0.1 @ 2014-11-27 18:19:09 +0530 processing photoscontroller#uploaded html   user load (0.4ms)  select  "users".* "users" "users"."id" = $1  order "users"."id" asc limit 1  [["id", 1]]   submit load (2.6ms)  select  "submits".* "submits"  order "submits"."id" asc limit 1   user load (2.2ms)  select  "users".* "users" "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 

update :

i set correct file path :

send_file "#{file.filename.file}" 

but gives error :

cannot read file #<carrierwave::sanitizedfile:0x007f570c2b9e58> 

is routes correct?

as per setup carrierwave should save file inside "/home/pubudu/projects/istockseller/public/uploads/tobereviewed/thpubs/#{model.user.username.downcase}/somefile.ext"

so, ideally code should be

send_file "#{rails.root}/public/#{file.image.url}" 

assuming upload column image.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -