ruby on rails - Save a local attachment on the server -


though paperclip gem used easy file uploads, have similar requirement @ server side. have generated image @ server , want save in various styles configured in paperclip options.

i have generated migration , model looks this:

attr_accessible :genimg has_attached_file :genimg   styles: { mini: '48x48>', small: '100x100>',             product: '240x240>', large: '600x600>' },   default_style: :product   url: '/images/:basename.:extension',   path: ':rails_root/app/assets/images/:basename.:extension'   convert_options: { all: '-strip -auto-orient' } 

is there way can save local image in various formats using paperclip. how can so? if that's not possible, other possible way try out?

class yourcontroller < actioncontroller::base   def your_action     @image = image.find 1 # (might other way how asset)      file_path = '/path/to/your/file'     file      = file.open(file_path, 'r')      @image.asset = file     @image.save   end end 

in console might do:

image.new(:data => file.new(path_to_your_file, "r")) 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -