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

matthibcn matthibcn at gmail.com
Thu Feb 1 15:45:20 EST 2007


Hi Ezra,

thank you very much for your reply as it saves me another few hours if 
not stays just get back my old working code ... and don´t try further.

First of I was coming around your plugin for cornjobstuff and it works 
great, so one time installed and reading through the www about it I came 
also across various blogentries about it, and one mentioned that 
backgrounDRb is for much more than jst cronjobs as imageprocessing, 
massmailing ..and conclued: for everything what takes a bit longer

So maybe i was misinterpreting this, my fault

The progressbar wasnt the reason i tried with backgrounDRb, it was just 
a wild guess that it would be somewhat faster that way

But, you are right, progressbars are like the state of the art today for 
imageuploading, so I am better of from backgrounDRb for that and 
spending my time in the mongrel_upload_progress gem for such feature

Once again, thanks for the reply and the great plugin

matthias

Ezra Zygmuntowicz schrieb:
> 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