How can I create a custom mail processor?

I need to do some post-processing when loading a file that is not images - in paperclip I may have a custom post processor, but I cannot find a way to do this in wavewave.

Ruby 1.9.3, Rails 3.2.7, and CarrierWave 0.6.2.

+5
source share
2 answers

The OP question was how to handle files that are not images.

Please see this source file on GitHub: carrierwave / lib / carrierwave / uploader / processing.rb and check the comments.

You will create your own subclass of the CarrierWave class and set it in your model as follows:

  def MyModel < ActiveRecord::Base

    # this is where the uploaded file will be available in your model,
    # as a `MyUploader` instance:
    #
    mount_uploader :uploaded_file, MyUploader

    ... 
  end

, ActiveRecord :uploaded_file. , :uploaded_file CarrierWave .

:

  class MyUploader < CarrierWave:Uploader::Base
    process :my_custom_processing => [param1,param2,param3]

    def my_custom_processing(param1,param2,param3)
      ...
      # e.g. you could call a method which is defined elsewhere,
      # which operates on a file:
      my_nifty_file_processor( self.uploaded_file ) 
      #
      # or you could just do this directly:
      uploaded_data = self.uploaded_file.read
      ...
    end
  end

my_nifty_file_processor read , .

CarrierWave read Uploader (= ), .

:

ActiveRecord , .

, :

      self.model

, , AR.

+6

All Articles