1

I am using Paperclip , and paperclip-ffmpeg for processing uploads. Below is my code

class Asset < ActiveRecord::Base

 belongs_to :profile  
 has_attached_file :photo, :styles => {
      :mobile => {:geometry => "400x300", :format => 'mp4', :streaming => true}
  }, :processors => [:ffmpeg]


 validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png',  'image/gif', 'application/msword', 'application/pdf', 'video/x-flv']

end

when i upload image or video file then it is working properly. But when i upload PDF or doc

file, this error occurs.

       "uninitialized constant Paperclip::Error" 

Any help??

Or How i can put if condition validation if upload file is PDF or Doc. Then i can skip this

below code. Because this is cause of error when file type is PDF or Doc.

        ":styles => {
      :mobile => {:geometry => "400x300", :format => 'mp4', :streaming => true}
  }, :processors => [:ffmpeg]" 

Thanks

Kashiftufail
  • 10,815
  • 11
  • 45
  • 79
  • Have you got any logs for this? – Richard Peck May 07 '14 at 08:53
  • Command :: ffmpeg -i '/tmp/stream20140507-5233-1qu3jll.doc' -y '/tmp/stream20140507-5233-1qu3jll20140507-5233-1nbuoe4.mp4' Completed 500 Internal Server Error in 211.7ms NameError (uninitialized constant Paperclip::Error): app/controllers/job_seeker_controller.rb:126:in `new' app/controllers/job_seeker_controller.rb:126:in `new_resume' – Kashiftufail May 07 '14 at 08:58
  • 1
    @RichPeck above will work for you? – Kashiftufail May 07 '14 at 08:59
  • @RichPeck How can i put lambda condition with this? has_attached_file :photo, :styles => { :mobile => {:geometry => "400x300", :format => 'mp4', :streaming => true} }, :processors => [:ffmpeg] #for skipping ffmpeg processor with doc file – Kashiftufail May 07 '14 at 09:02
  • Hmmmmmmmmm the person who'd know about this is [`@kirti thorat`](http://stackoverflow.com/users/1012097/kirti-thorat). I'll send her a message on LinkedIn to see if she knows what `Paperclip::Error` is – Richard Peck May 07 '14 at 09:03
  • The problem seems to be that you're calling the `ffmpeg` processor, and it's raising an error, which cannot be processed as `Paperclip::error` cannot be found – Richard Peck May 07 '14 at 09:04

1 Answers1

1

I have asked Kirti Thorat on LinkedIn for you - she may be better placed than me to deal with Paperclip::Error problem


Or How i can put if condition validation if upload file is PDF or Doc

In terms of formatting your has_attached_file method to use a lambda, here's what we've done before:

has_attached_file :attachment,
     styles:        lambda { |a| a.instance.is_image? ? {:small => "x200>", :medium => "x300>", :large => "x400>"}  : {:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10}, :medium => { :geometry => "300x300#", :format => 'jpg', :time => 10}}},
     :processors => lambda { |a| a.is_video? ? [ :ffmpeg ] : [ :thumbnail ] }

def is_video?
 attachment.instance.attachment_content_type =~ %r(video)
end

def is_image?
 attachment.instance.attachment_content_type =~ %r(image)
end

This is relatively old code, so to keep you updated, Paperclip 4.0 released a new media spoofing feature, which basically checks your file directly (instead of the extension) for its content type. Kirti knows a lot about that, so it will be best to wait for her answer

I could have a crack at it if you wanted me to

Richard Peck
  • 76,116
  • 9
  • 93
  • 147