Rabbit56
Rabbit56

Reputation: 196

Heroku - Ruby on Rails - Upload of pictures

we are working on the PYL project ( a kind of social network dealing with pictures users can modify ). we have the code for some function of the website which work on the localhost ( upload, modify...) but when we want to put in in the internet through Heroku the code doesn't work for the upload !

(I use paperclip)

In fact, the webside ask the user to upload the file, he can chose the picture hi wants but when he submits, the picture doesn't appear and we have an error !

The error : "We're sorry, but something went wrong." Here my heroku logs :

2013-12-04T10:12:16.681348+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
2013-12-04T10:12:16.680828+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
2013-12-04T10:12:16.681348+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/rack/logger.rb:21:in `block in call'
2013-12-04T10:12:16.680828+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
2013-12-04T10:12:16.681348+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/tagged_logging.rb:67:in `block in tagged'
2013-12-04T10:12:16.681348+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/tagged_logging.rb:25:in `tagged'
2013-12-04T10:12:16.681556+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/cache/strategy/local_cache.rb:83:in `call'
2013-12-04T10:12:16.681556+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:97:in `call'
2013-12-04T10:12:16.681556+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
2013-12-04T10:12:16.681556+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
2013-12-04T10:12:16.681556+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
2013-12-04T10:12:16.681556+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
2013-12-04T10:12:16.681556+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
2013-12-04T10:12:16.681556+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:511:in `call'
2013-12-04T10:12:16.681348+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/rack/logger.rb:21:in `call'
2013-12-04T10:12:16.681348+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/request_id.rb:21:in `call'
2013-12-04T10:12:16.681925+00:00 app[web.1]:
2013-12-04T10:12:16.681925+00:00 app[web.1]:
2013-12-04T10:12:16.681925+00:00 app[web.1]: ActionController::RoutingError (uninitialized constant PhotoController):
2013-12-04T10:12:16.681925+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:226:in `block in constantize'
2013-12-04T10:12:16.681925+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:224:in `each'
2013-12-04T10:12:16.681925+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:226:in `const_get'
2013-12-04T10:12:16.681925+00:00 app[web.1]:
2013-12-04T10:12:16.681556+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
2013-12-04T10:12:16.681556+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/static.rb:64:in `call'
2013-12-04T10:12:16.682067+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/journey/router.rb:59:in `each'
2013-12-04T10:12:16.682067+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/routing/route_set.rb:44:in `call'
2013-12-04T10:12:16.682067+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/journey/router.rb:71:in `block in call'
2013-12-04T10:12:16.682067+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/routing/route_set.rb:66:in `controller'
2013-12-04T10:12:16.681925+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:224:in `constantize'
2013-12-04T10:12:16.681925+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/routing/route_set.rb:76:in `controller_reference'
2013-12-04T10:12:16.681925+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:224:in `inject'
2013-12-04T10:12:16.682067+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/journey/router.rb:59:in `call'
2013-12-04T10:12:16.682489+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/flash.rb:241:in `call'
2013-12-04T10:12:16.682067+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/conditionalget.rb:25:in `call'
2013-12-04T10:12:16.682067+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/routing/route_set.rb:655:in `call'
2013-12-04T10:12:16.682067+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
2013-12-04T10:12:16.682067+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
2013-12-04T10:12:16.682067+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call'
2013-12-04T10:12:16.682489+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'
2013-12-04T10:12:16.682720+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
2013-12-04T10:12:16.682489+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
2013-12-04T10:12:16.682489+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
2013-12-04T10:12:16.682489+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/cookies.rb:486:in `call'
2013-12-04T10:12:16.682489+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/query_cache.rb:36:in `call'
2013-12-04T10:12:16.682489+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
2013-12-04T10:12:16.682489+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
2013-12-04T10:12:16.682489+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:80:in `run_callbacks'
2013-12-04T10:12:16.682489+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:373:in `_run__2980751904426103993__call__callbacks'
2013-12-04T10:12:16.682720+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
2013-12-04T10:12:16.682720+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/rack/logger.rb:21:in `call'
2013-12-04T10:12:16.682720+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
2013-12-04T10:12:16.682720+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/tagged_logging.rb:67:in `block in tagged'
2013-12-04T10:12:16.682720+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/tagged_logging.rb:25:in `tagged'
2013-12-04T10:12:16.682720+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/rack/logger.rb:38:in `call_app'
2013-12-04T10:12:16.682720+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/rack/logger.rb:21:in `block in call'
2013-12-04T10:12:16.682720+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/tagged_logging.rb:67:in `tagged'
2013-12-04T10:12:16.682720+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/request_id.rb:21:in `call'
2013-12-04T10:12:16.683138+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
2013-12-04T10:12:16.683138+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
2013-12-04T10:12:16.683138+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:511:in `call'
2013-12-04T10:12:16.683138+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:97:in `call'
2013-12-04T10:12:16.683138+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
2013-12-04T10:12:16.683138+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
2013-12-04T10:12:16.683138+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/static.rb:64:in `call'
2013-12-04T10:12:16.683138+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
2013-12-04T10:12:16.683138+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/cache/strategy/local_cache.rb:83:in `call'
2013-12-04T10:12:16.683138+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
2013-12-04T10:12:16.683368+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
2013-12-04T10:12:16.683368+00:00 app[web.1]:
2013-12-04T10:12:16.683368+00:00 app[web.1]: Started GET "/photos/new" for 130.240.96.136 at 2013-12-04 10:12:16 +0000
2013-12-04T10:12:16.683368+00:00 app[web.1]: Started GET "/photos/new" for 130.240.96.136 at 2013-12-04 10:12:16 +0000
2013-12-04T10:12:16.683368+00:00 app[web.1]:
2013-12-04T10:12:16.683368+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
2013-12-04T10:12:16.683883+00:00 app[web.1]: Processing by PhotosController#new as HTML
2013-12-04T10:12:16.683883+00:00 app[web.1]: Processing by PhotosController#new as HTML
2013-12-04T10:12:17.489031+00:00 app[web.1]:   Rendered photos/new.html.erb within layouts/application (55.0ms)
2013-12-04T10:12:17.489031+00:00 app[web.1]:   Rendered photos/new.html.erb within layouts/application (55.0ms)
2013-12-04T10:12:17.490529+00:00 app[web.1]: Completed 200 OK in 807ms (Views: 58.3ms | ActiveRecord: 727.6ms)
2013-12-04T10:12:17.490529+00:00 app[web.1]: Completed 200 OK in 807ms (Views: 58.3ms | ActiveRecord: 727.6ms)
2013-12-04T10:12:17.888402+00:00 heroku[router]: at=info method=GET path=/assets/application-f5232013e5e376066072368171046674.css host=peaceful-coast-9294.herokuapp.com fwd="130.240.96.136" dyno=web.1 connect=1ms service=13ms status=200 bytes=106699
2013-12-04T10:12:18.158382+00:00 heroku[router]: at=info method=GET path=/assets/application-500ecc3f86fcdef878a049cb9ca9929b.js host=peaceful-coast-9294.herokuapp.com fwd="130.240.96.136" dyno=web.1 connect=11ms service=18ms status=200 bytes=106270
2013-12-04T10:12:18.880421+00:00 heroku[router]: at=info method=GET path=/favicon.ico host=peaceful-coast-9294.herokuapp.com fwd="130.240.96.136" dyno=web.1 connect=1ms service=4ms status=200 bytes=0
2013-12-04T10:12:30.248880+00:00 app[web.1]: Processing by PhotosController#create as HTML
2013-12-04T10:12:30.248975+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"IXqTzLLBggUvR7A1OCGfwtJ9PGhZaQTi3xY1ctHCmy4=", "photo"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007f73978a31f0 @tempfile=#<Tempfile:/tmp/RackMultipart20131204-2-mj3wtf>, @original_filename="555.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"photo[image]\"; filename=\"555.png\"\r\nContent-Type: image/png\r\n">}, "commit"=>"Create Photo"}
2013-12-04T10:12:30.250242+00:00 app[web.1]: Completed 500 Internal Server Error in 1ms
2013-12-04T10:12:30.248880+00:00 app[web.1]: Processing by PhotosController#create as HTML
2013-12-04T10:12:30.247018+00:00 app[web.1]: Started POST "/photos" for 130.240.96.136 at 2013-12-04 10:12:30 +0000
2013-12-04T10:12:30.251377+00:00 app[web.1]:
2013-12-04T10:12:30.250242+00:00 app[web.1]: Completed 500 Internal Server Error in 1ms
2013-12-04T10:12:30.247018+00:00 app[web.1]: Started POST "/photos" for 130.240.96.136 at 2013-12-04 10:12:30 +0000
2013-12-04T10:12:30.251377+00:00 app[web.1]:
2013-12-04T10:12:30.251377+00:00 app[web.1]: Paperclip::Error (Photo model missing required attr_accessor for 'image_file_name'):
2013-12-04T10:12:30.251377+00:00 app[web.1]:
2013-12-04T10:12:30.251377+00:00 app[web.1]:
2013-12-04T10:12:30.248975+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"IXqTzLLBggUvR7A1OCGfwtJ9PGhZaQTi3xY1ctHCmy4=", "photo"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007f73978a31f0 @tempfile=#<Tempfile:/tmp/RackMultipart20131204-2-mj3wtf>, @original_filename="555.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"photo[image]\"; filename=\"555.png\"\r\nContent-Type: image/png\r\n">}, "commit"=>"Create Photo"}
2013-12-04T10:12:30.251377+00:00 app[web.1]:   app/controllers/photos_controller.rb:27:in `create'
2013-12-04T10:12:30.251377+00:00 app[web.1]:
2013-12-04T10:12:30.251377+00:00 app[web.1]: Paperclip::Error (Photo model missing required attr_accessor for 'image_file_name'):
2013-12-04T10:12:30.251377+00:00 app[web.1]:   app/controllers/photos_controller.rb:27:in `create'
2013-12-04T10:12:30.251377+00:00 app[web.1]:

What is the problem ? The database ? Do I have to create a Amazon S3 account to be abble to upload and save images from my website ? It should work even without a Amazon S3 account isn't it ?

Thank you

Upvotes: 1

Views: 208

Answers (3)

Rabbit56
Rabbit56

Reputation: 196

To respond to my own question, in fact you can upload a picture on Heroku but it will be a temporary file and will be send to trash.(I did'nt make it works with paperclip but I know that for example with carrierwave it works).

I solved my problem making work the upload thing with amazon AWS S3 ( to store permanently my files).

Upvotes: 0

stephenmurdoch
stephenmurdoch

Reputation: 34613

As @TheChamp said, heroku's filesystem is ephemeral, but you should also beware that your logs display the following:

ActionController::RoutingError (uninitialized constant PhotoController):

Might want to investigate that if you find this issue still exists after switching to S3.

Upvotes: 1

davegson
davegson

Reputation: 8331

Heroku doesn't provide you with webspace for uploads, your assumption was right, setting it up with Amazon S3 is the way to go:

Setting up S3 with Paperclip

Upvotes: 1

Related Questions