jrgifford / delayed_paperclip

Process your Paperclip attachments in the background with delayed_job or Resque.
http://www.jstorimer.com/ruby/2010/01/30/delayed-paperclip.html
MIT License
404 stars 155 forks source link

RoutingError on all my public/system.... image files #132

Open casertap opened 9 years ago

casertap commented 9 years ago

Hi, I wanted to use delayed_paperclip to relay the processing of video with paperclip-ffmpeg. My images files are served statically (I bypass rails) so I do not want my images to be affected by delayed_apaperclip.

  has_attached_file :video, :styles => {
      :mp4 => { :format => 'mp4', :convert_options => { :output => { :vcodec => 'libx264', :acodec => 'copy' } } },
      :ogg => { :format => 'ogg', :auto_rotate => true  },
      :webm => { :format => 'webm', :auto_rotate => true  },
      :flv => { :format => 'flv', :convert_options => { :output => { :ar => 44100 } }, :auto_rotate => true  },
      :thumb => { :geometry => "300x300#", :format => 'jpg', :time => 1, :auto_rotate => true }
    }, :processors => [: transcoder]
  validates_attachment_content_type :video, :content_type => ["video/mp4", "application/ogg", "video/webm", "video/x-flv", "video/quicktime", "image/jpg"]
  process_in_background :video

generate a stack like this on all my pictures when they are loaded on the page:

ActionController::RoutingError (No route matches [GET] "/system/users/profile_pictures/000/000/002/fit/image.jpg%3F1421305880"):
  actionpack (4.1.9) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.1.9) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'

I use Redis with Resque (I tested this part and everything work)

gem 'paperclip', "4.2.1"
gem 'paperclip-av-transcoder', "0.6.2"
katafrakt commented 9 years ago

It seems that your images are not served statically (otherwise those requests would not hit Rails routing at all). Could you post relevant config of your web server (apache, nginx or whatever you are using)?

casertap commented 9 years ago

Ho yes you are totally right. I'm in a transition phase where I try of migrate the application to having all the asset served statically but it is not the case yet. My bad for having say that in the first comment.

The thing is that I get this error in development mode. So in this mode there is no apache or nginx involved.

katafrakt commented 9 years ago

And you don't happen to have config.serve_static_files set to false in your development.rb? Are you sure that files in question really exist? (Note that you have %3F instead of ? at the end of request path. Where does it come from?)

casertap commented 9 years ago

I did not set the config.serve_static_assets in my development environment so it has the default value. The %3F that you noticed is strange. I did have a problem with saving iphone emoji in db and change the encoding to uf8 to utf8mb4 but I do not think it is related here.

My app runs just fine. the problems happen when I add delayed_paperclip in my gem file and I bundle install. I do not even have to set the process_in_background to see the problem happening. It my be something related to the config

Here is my development.rb :

MyApp::Application.configure do
  config.cache_classes = false

  config.eager_load = false

  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  config.action_mailer.raise_delivery_errors = false

  config.active_support.deprecation = :log

  config.action_dispatch.best_standards_support = :builtin

  config.active_record.mass_assignment_sanitizer = :strict

  config.assets.compress = false

  config.assets.debug = true

  config.action_mailer.default_url_options = { :host => 'localhost:3000' }

  config.action_mailer.delivery_method = :letter_opener
  config.action_mailer.asset_host = "http://localhost:3000"

  config.active_support.deprecation = :stderr
  config.lograge.enabled = true
  config.lograge.formatter = Lograge::Formatters::Logstash.new
  config.lograge.custom_options = lambda do |event|
    unwanted_keys = %w[format action controller]
    params = event.payload[:params].reject { |key,_| unwanted_keys.include? key }
    {:params => params }
  end
  #config.middleware.use PrettyJsonResponse
  config.middleware.use Rack::Cors do
    allow do
      origins 'localhost:9000'
      resource '*', :headers => :any, :methods => [:get, :post, :options, :delete]
    end
  end
end
Paperclip.options[:command_path] = "/usr/local/bin/ffmpeg"
class ActionDispatch::Request
  def remote_ip
    "178.199.183.90"
  end
end

Gemfile

gem 'paperclip', "4.2.1"
gem 'paperclip-av-transcoder', "0.6.2"
gem 'cocaine', "0.5.3"
casertap commented 9 years ago

Maybe you can solve my problem in a different way. What I want at the end is process the video asynchronously.

I'm using gem 'paperclip-av-transcoder', "0.6.2" for my video processing.

I simply need to write this code to have my video converted into many formats:

    has_attached_file :video, :styles => {
      :mp4 => { :format => 'mp4', :convert_options => { :output => { :vcodec => 'libx264', :acodec => 'copy' } } },
      :ogg => { :format => 'ogg', :auto_rotate => true  },
      :webm => { :format => 'webm', :auto_rotate => true  },
      :flv => { :format => 'flv', :convert_options => { :output => { :ar => 44100 } }, :auto_rotate => true  },
      :thumb => { :geometry => "300x300#", :format => 'jpg', :time => 1, :auto_rotate => true }
    }, :processors => [:transcoder]

But this code is synchrone and the user that upload the video is stuck during the conversion.

I would like to add an asynch wrapper (worker) around :transcoder so I can call:

    has_attached_file :video, :styles => {... }, :processors => [:wrapper_transcoder_worker]

I have installed resque and redis and everything work.

How can I create this asynch wrapper (worker) around :transcoder ? You probably did something similar with delayed_paperclip, right?

katafrakt commented 9 years ago

Your issue seems to be the same as https://github.com/jrgifford/delayed_paperclip/issues/126. Try locking paperclip at 4.2.0 until delayed_paperclip gets patched.

casertap commented 9 years ago

Nice! thanks it works