[Backgroundrb-devel] file_column 2nd try....

Ezra Zygmuntowicz ezmobius at gmail.com
Thu Feb 1 15:18:02 EST 2007


Hey there-

	I think you have a misconception of what backgroundrb can be used  
for. There is no way to use backgroundrb to do a progress bar for a  
file upload. Because the entire image will have to be uploaded before  
rails will pass it to backgroundrb.

	Looking at your code I think you are better off not using  
backgroundrb and just doing what you are doing all in rails.

	Is that your goal? TO have a progress bar for file uploads? If so  
you are barking up the wrong tree sorry. You can look at the  
mongrel_upload_progress gem to see about progress bars for file uploads.


Cheers-
-Ezra

On Feb 1, 2007, at 10:50 AM, matthibcn wrote:

> Looks like my first question a couple of days ago wasn´t very clever
> asked, at least very sucessfull....
>
> So, anyway...i will try it again:
>
> I have to prefix that I am far away from fully understanding the  
> overall
> concept yet, and there´s no way to get some hints in the www so  
> far, at
> least my resaerches dont lead to any helpfull stuff.
>
> image_controller.rb:
>
> def create
> MiddleMan.new_worker :class => :image_worker,
> :job_key => :upload_img,
> :args => { :image => params[:image]}
> worker = ::MiddleMan.worker(:upload_img)
> end
>
> image_worker.rb
>
> require 'RMagick'
>
> class ImageWorker < BackgrounDRb::Worker::RailsBase
>
> ##attr_accessor :text
>
> def do_work(args)
> ##@text = args[:text]
> @image = Image.new(args[:image])
> @image.dimensions
> @image.save
> end
>
> def progress
> results[:progress]
> end
> end
> ImageWorker.register
>
> image.rb
>
> require 'RMagick'
>
> class Image < ActiveRecord::Base
> belongs_to :user
>
> validates_filesize_of :image, :in => 15.kilobytes..1.megabyte
> validates_file_format_of :image, :in => ["gif", "png", "jpg"]
>
> file_column :image, :magick => {:versions => {"thumb" => "150x100",
> "picture" => "600x450>"}}
>
> def dimensions
> img = Magick::Image.read(self.image).first
> if img.columns >= img.rows
> ratio = img.columns.to_f / 600
> else
> ratio = img.rows.to_f / 450
> end
> self.width = ((img.columns / ratio)+10).to_i
> self.height = ((img.rows / ratio)+10).to_i
> end
>
> end
>
> So, this isn´t working...in fact I would be surprised if it would be
> that easy, as I just shifet code away from the controller to the  
> worker...
>
> Ok:
>
> when submitting the uploadform at least the worker get fired and  
> passed
> the args as expected, as I can see in the backgroundrb_server.log:
>
> 20070201-10:47:29 (53830) Starting worker: image_worker upload_img
> (image_worker_upload_img)
> (imagecreated_on(2i)2created_on(3i)1created_on(4i)00created_on(5i) 
> 18updated_on(1i)2007updated_on(2i) 
> 2image_tempdescriptionbackgrounDRb33updated_on(3i) 
> 1imgnum007updated_on(4i)00image#<File:0x8d13028>updated_on(5i) 
> 18created_on(1i)2007)
>
> Now there are 2 questions:
>
> the image isnt uploaded, that is probably due to the fact that the
> file_columnPlugin isnt available for the backgrounDRbserver..
>
> My research turned out, that for the earlier version of the  
> backgrounDRb
> you had to insert
>
> //require File.dirname(__FILE__) + "/../../config/environment.rb"
> //
>
> in the scrip/backgroundrb/start script..there is no such script in the
> actuall version and i cant see where to put that now.
>
> So, anyway, also if the image isnt uploaded physically shouldnt i  
> expect
> at least an DB entry for the passed args as I call the save method on
> @image ??
>
> Further I think the dimension method should go also in the worker, but
> step by step, and I am still totaly lost, so I just ask you kindly  
> again
> to provide some input to enlighten me and others, as I guess that a  
> lot
> of ppl are still missing some real world examples except of some
> cronlike or outdated stuff
>
> best regards
>
> matthias
>
>
>
>
>
>
> _______________________________________________
> Backgroundrb-devel mailing list
> Backgroundrb-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/backgroundrb-devel

-- Ezra Zygmuntowicz 
-- Lead Rails Evangelist
-- ez at engineyard.com
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)




More information about the Backgroundrb-devel mailing list