Is Rails Paperclip image-only?
Are there rails libraries for managing ActiveRecord related file attachments?
I know paperclip, but this is primarily for images. They do mention audio and pdf files on the github page , but there is no further explanation regarding the use of different file types. Attributes such as :style
would change their meaning if you uploaded an audio file. Therefore, different file sizes will not be expressed in 2D, but in terms of bit rates.
Are there any alternatives to paperclip? Or maybe not just linking imagemagick to paperclip but ffmpeg for example?
source to share
The above question has more than one aspect. So I will try to answer them one by one.
Paperclip :: CPU
It is possible to use paperclip for files other than images. You can define custom imports by subclassing Paperclip :: Processor . The following code shows the minimal structure of a custom processor implementation. This can be adapted to any file type with custom options
.
module Paperclip
class FileContents < Processor
def initialize file, options = {}, attachment = nil
@file = file
@options = options
@instance = attachment.instance
@current_format = File.extname(attachment.instance.asset_file_name)
@basename = File.basename(@file.path, @current_format)
@whiny = options[:whiny].nil? ? true : options[:whiny]
end
def make
begin
# your import code (e.g. ocr or video resizing)...
@file
rescue StandardError => e
raise PaperclipError, "There was an error processing the file contents for #{@basename} - #{e}" if @whiny
end
end
end
end
paperclip and ffmpeg
Someone already wrote a paperclip processor for video files. Have a look at the paperclip-ffmpeg source to see how complex processors are written.
Alternatives
Here are some alternatives I've found:
Pro and Cons already discussed fooobar.com/questions/375879 / ... .
source to share
There's no reason you couldn't use Paperclip for other file types, but if you want an alternative, you can't go wrong with CarrierWave .
source to share