kbingman / paperclipped

Please note, this extension is no longer being developed. Please take a look at the radiant-clipped-extension instead. Radiant extension for managing assets and images with the Paperclip plugin.
Other
122 stars 64 forks source link

Error uploading large PDFs #35

Open trans opened 13 years ago

trans commented 13 years ago

When I try to upload a large PDF file (800K) there is a long delay after the upload is complete and then an Application Error occurs.

kbingman commented 13 years ago

This isn't enough information to help at all. Can you paste a the error stack trace? Have you made sure the the Radiant Config files allow files as large as the pdf? Do other files upload? Take a look at the mailing list, maybe there are some similar issues there.

trans commented 13 years ago

I've been looking everywhere for three days. It works fine for other types of files --I was able to upload a 15MB .gif for instance, no problem. I am also able to upload a 100KB PDF, but an 800K .pdf fails.

I will try to gather more information about the issue. Currently this is happening on a remote host in production mode. I will setup a local install and see if it happens there too.

kbingman commented 13 years ago

Download the log files, the will show the 500 error and tell you what is happening. /log/production. I could be the pdf, as well. Try it with a different, but also large pdf.

trans commented 13 years ago

I think I may have narrowed down the issue. When installing on my host I installed the Paperclipped extension before the Settings extension. (Also, in try to adjust for that I ran rake radiant:extensions:migrate which somehow installed a bunch of language extensions I did not want.) I've noticed two strange things about my hosted radiant app vs my local app. First the icon is missing from Settings entries. Second the "Create Asset" button changed at one point and now says "Create {{name}}".

I think I need to back up somehow and install the Settings extension before the Paperclipped extension and see if that fixes it. Do you have any advice.thoughts on this?

kbingman commented 13 years ago

This has nothing to do with your problem. Sounds like you have two different versions of paperclipped and perhaps your environment.rb file is wrong. LikeI said, download the log files.

trans commented 13 years ago
Processing Admin::AssetsController#new (for 70.119.230.177 at 2011-01-30 11:57:56) [GET]
  Parameters: {"action"=>"new", "controller"=>"admin/assets"}
Rendering template within layouts/application
Rendering admin/assets/new
Completed in 33ms (View: 30, DB: 1) | 200 OK [http://cafemezz.com/admin/assets/new]

Processing Admin::AssetsController#create (for 70.119.230.177 at 2011-01-30 11:58:29) [POST]
  Parameters: {"commit"=>"Create {{name}}", "action"=>"create", "authenticity_token"=>"S7uzUc5B6U6OP1nBUIyBFXI8DHdF3HUhyFvM1uUjinE=", "controller"=>"admin/as
sets", "asset"=>{"title"=>"PDF Seasonal", "caption"=>"", "asset"=>#}}
[paperclip] identify '-format' '%wx%h' '/tmp/stream,31705,0.pdf[0]' 2>/dev/null
[paperclip] convert '/tmp/stream,31705,0.pdf[0]' '-resize' '42x' '-crop' '42x42+0+21' '+repage' '/tmp/stream,31705,0,31705,0.png' 2>/dev/null
[paperclip] identify '-format' '%wx%h' '/tmp/stream,31705,0.pdf[0]' 2>/dev/null
[paperclip] convert '/tmp/stream,31705,0.pdf[0]' '-resize' '100x100>' '/tmp/stream,31705,0,31705,1.png' 2>/dev/null
[paperclip] identify '-format' '%wx%h' '/tmp/stream,31705,0.pdf[0]' 2>/dev/null
[paperclip] convert '/tmp/stream,31705,0.pdf[0]' '-resize' '150x100>' '/tmp/stream,31705,0,31705,0' 2>/dev/null

ActiveRecord::StatementInvalid (Mysql::Error: MySQL server has gone away: INSERT INTO `assets` (`updated_by_id`, `created_at`, `title`, `asset_file_name`, `a
sset_file_size`, `created_by_id`, `updated_at`, `asset_content_type`, `caption`) VALUES(NULL, '2011-01-30 17:59:24', 'PDF Seasonal', 'seasonal.pdf', 1343447,
 1, '2011-01-30 17:59:24', 'application/pdf', '')):
  vendor/extensions/paperclipped/app/controllers/admin/assets_controller.rb:24:in `create'
  radiant (0.9.1) vendor/plugins/haml/rails/./lib/sass/plugin/rails.rb:20:in `process'
  passenger (2.2.15) lib/phusion_passenger/rack/request_handler.rb:92:in `process_request'
  passenger (2.2.15) lib/phusion_passenger/abstract_request_handler.rb:207:in `main_loop'
  passenger (2.2.15) lib/phusion_passenger/railz/application_spawner.rb:441:in `start_request_handler'
  passenger (2.2.15) lib/phusion_passenger/railz/application_spawner.rb:381:in `handle_spawn_application'
  passenger (2.2.15) lib/phusion_passenger/utils.rb:252:in `safe_fork'
  passenger (2.2.15) lib/phusion_passenger/railz/application_spawner.rb:377:in `handle_spawn_application'
  passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:352:in `__send__'
  passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
  passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'
  passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:163:in `start'
  passenger (2.2.15) lib/phusion_passenger/railz/application_spawner.rb:222:in `start'
  passenger (2.2.15) lib/phusion_passenger/spawn_manager.rb:253:in `spawn_rails_application'
  passenger (2.2.15) lib/phusion_passenger/abstract_server_collection.rb:126:in `lookup_or_add'
  passenger (2.2.15) lib/phusion_passenger/spawn_manager.rb:247:in `spawn_rails_application'
  passenger (2.2.15) lib/phusion_passenger/abstract_server_collection.rb:80:in `synchronize'
  passenger (2.2.15) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
  passenger (2.2.15) lib/phusion_passenger/spawn_manager.rb:246:in `spawn_rails_application'
  passenger (2.2.15) lib/phusion_passenger/spawn_manager.rb:145:in `spawn_application'
  passenger (2.2.15) lib/phusion_passenger/spawn_manager.rb:278:in `handle_spawn_application'
  passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:352:in `__send__'
  passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
  passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'

Rendering /home/cafemezz/radiant/public/500.html (500 Internal Server Error)

Processing SiteController#show_page (for 166.137.8.84 at 2011-01-30 11:59:42) [GET]
  Parameters: {"url"=>["pdf", "lunch.pdf"], "action"=>"show_page", "controller"=>"site"}
Rendering template within layouts/application
Rendering site/not_found (404)
Completed in 36ms (View: 2, DB: 3) | 404 Not Found [http://www.cafemezz.com/pdf/lunch.pdf]
kbingman commented 13 years ago

Your server is timing out.

ActiveRecord::StatementInvalid (Mysql::Error: MySQL server has gone away

It creates the asset and record, but cannot insert it into the MySQL database. I looks like the request is taking over a minute. Does this file upload to the local copy? We have pdfs with over 10mb, but then again, we run our own servers.

trans commented 13 years ago

Yes. It works with the local server. My shared host seems to be getting bogged down in the converts. It takes about a minute or so for a large PDF. I will contact my host and see if the can do anything about the timeout.

But I also wonder why Paperclipped is trying to create thumbnails for PDF files? Does that actually work? I looked at the one of assets folders for my local app, for a file called cocktails.pdf it created three other files: cocktails_icon.png, cocktails_normal.pdf and cocktails_thumbnail.png. So it does appear to work, though cocktails_normal.pdf seems out of place. Are these images of the used at all? Maybe they don't need to be created?

kbingman commented 13 years ago

Checkout the paperclip gem itself. You can probably turn this off.

https://github.com/thoughtbot/paperclip

trans commented 13 years ago

Finally got it working!!! I added the following code to vendor/extensions/paperclipped/app/models/assets.rb in the Assets class:

before_post_process :not_pdf?  # should be placed after line with has_attached_file 

def not_pdf?
  return false if (asset_content_type =~ /application\/.*pdf/)
end

So it's no longer running the PDF through convert.

The only issue I have now is that somehow in the process of working on this, the "Create Asset" button now says "Create {{name}}". Something to do with the language extensions I am sure, but why would it not be putting in the variable for name rather than showing {{name}}?

kbingman commented 13 years ago

Check out the yaml file in locale/en.yaml. It probably has the wrong translation. In the view, check the key and then correct it in the en.yaml file.

trans commented 13 years ago

I looked at the view, the button is being generated with = save_model_button(@asset). That's a built-in Radiant method that is building the button's text from @asset.class.name (see https://github.com/radiant/radiant/blob/master/app/helpers/application_helper.rb#L26). I've grep'd around, but can't find where it's getting {{name}} from.