Mongrel upload progress: how to validate

Hi there,

Another Mongrel upload progress question… I hope you don’t mind.
(see http://mongrel.rubyforge.org/docs/upload_progress.html).

My problem is the following, before uploading the file I want to check
if it already exists. This is done via a validation in the Myfile model:

validates_uniqueness_of :filename, :scope => ‘folder_id’

When I didn’t use upload progress yet this worked fine, but now the
validation doesn’t get done until after the file is uploaded. Obviously
this is behaviour I don’t want. It seems the progress starts before
anything else because of the following in the config file :in_front =>
true. Is there anyway to do this validation before starting the upload
progress? At the moment I’m clueless…

Thanks!!

Mischa.

On Nov 27, 2006, at 3:33 PM, Mischa B. wrote:

validates_uniqueness_of :filename, :scope => ‘folder_id’

Mischa.

Hey Mischa-

The mongrel upload progress has to be in_front => true to work. That

is the only way for it to know the status of the upload. Mongrel
keeps an internal progress updater going and tells the upload
progress handler to increment the progress bar in the browser. But
control doesn’t come to your rails app until after the entire upload
is done. AFAIK there is no easy way to do the validation you want to
do before the prorgess bar is done and the file is already uploaded :confused:

Cheers-
– Ezra Z.
– Lead Rails Evangelist
[email protected]
– Engine Y., Serious Rails Hosting
– (866) 518-YARD (9273)

Thanks for the feedback.

Now I’m thinking of using Ajax to do the check after the file to upload
has been selected and before the upload button has been clicked. Does
anyone have experience with this? Is this possible?

Thanks,

Mischa.

is done. AFAIK there is no easy way to do the validation you want to
do before the prorgess bar is done and the file is already uploaded :confused: