I have done a very similar thing to this, allowing people to upload an image
from either their hard drive or an image from a url, I used file column to
handle the validations on both, but I have to do some tweaks on the URL
image before I save it to the file column, when you upload any file to a cgi
server it is kept in the servers temp dir until you do something with it,
knowing this you can tweak hat file until you need it
so one trick could be to upload your own temp img, without using file_column
for the upload, validate it then copy it to the file column if it validates
(file column does this but you want access to ''your'' own temp
file)
to do this don''t use the file_column helper to upload, just use the
basic
rails helper or just write it in html
this is what file_column does in the background, so do something similar for
the field ''img_name'' in the model ''tile''
<input id="tile_img_name_temp" name="tile[img_name_temp]"
type="hidden"><input id="tile_img_name"
name="tile[img_name]"
size="30" type="file">
this is a bit of a hack, but create another column in your img db
table called img2 or something and use this for storing the temp image
e.g <input id="tile_img_name2" name="tile[img_name2]"
size="30" type="file">
you need to do this because as soon as FileColumn sees anything initilised
to its column img_name it will grab it and run with it...
then in your upload action, create an instance with the params
@tile = Tile.new(params[:tile])
@tile.img_name2 should be pointing to the temp img
validate the temp img, as you please, it is stored as a TempFile in the
servers file systems temp directory
if it all checks out...copy the temp image to the file_column using the
system commands in FileUtils, add require ''fileutils'' to your
rails app to
use this
I can give you a better example later on when I get home, I was doing a
similar sort of thing last night and did not commit the code to my svn so
cant have a look at it right now...
hope this gets you going in the right direction
dion
www.blogsaic.com
On 7/31/06, adam <adamjroth@gmail.com> wrote:>
> file_column is great -- but I need a way to run through the validations
> (ie: validates_file_format_of) before saving. That is, when a user first
> uploads an image it is displayed in the view but not
''saved'' until they
> click the ''Save'' button on the form. I want to display an
error
> message/disable the ''Save'' button if the file they just
uploaded fails
> basic validations (not correct file format, filesize too large).
I''m
> just not sure how to access/run-thru validations before calling
> object.save.
>
> Any ideas?
> Adam
>
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060731/08ca4be0/attachment.html