# File\_column

**URL:** <https://www.ruby-forum.com/t/file-column/76691>\
**Category:** Rails\
**Created:** [March 4, 2006, 3:22pm UTC](https://www.ruby-forum.com/t/file-column/76691 "2006-03-04T15:22:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shark\_Fin\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@Shark\_Fin\_S](https://www.ruby-forum.com/u/Shark_Fin_S)\
**Post date:** [March 4, 2006, 3:22pm UTC](https://www.ruby-forum.com/t/file-column/76691/1 "2006-03-04T15:22:52Z")

</div>

Restricting size of an uploaded file, is how is that possible? If I  
do not want a user to upload a file larger than X bytes, can it  
easily be done?

If I also would like restrict the types of files that can be  
uploaded, how may I do so?

Thank you,

Sharkie

---

<div class="post-metadata">

**Author:** ![Shark\_Fin\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@Shark\_Fin\_S](https://www.ruby-forum.com/u/Shark_Fin_S)\
**Post date:** [March 4, 2006, 4:14pm UTC](https://www.ruby-forum.com/t/file-column/76691/2 "2006-03-04T16:14:14Z")

</div>

file\_column from trunk has optional file\_size validation. AFAIK,  
validation  
is done before saving, in that case, you are still uploading the file. A  
better option would be if the webserver would cancel the upload, when  
the  
max filesize is reached. I am using Lighttpd, which has no such upload  
mod,  
but maybe apache has some some ? Or try to convince  
Zed[http://www.zedshaw.com/](http://www.zedshaw.com/)to put some sophisticated upload  
functionality into mongrel.

Filetype can be restricted with a bit of javascript and regular  
expression  
when the Input field of the File upload form changes.  
This[http://blog.caboo.se/articles/2006/02/23/integrate-rails-modules-with-javascript-objects](http://blog.caboo.se/articles/2006/02/23/integrate-rails-modules-with-javascript-objects)might  
help you to understand how you need to aproach that. Or if you like  
flash, you can rely on flashplayer 8 for highly configurable file-upload  
(with smooth progress indicator), but that wil require a lot of  
Javascript  
for the integration.

---

<div class="post-metadata">

**Author:** ![Shark\_Fin\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@Shark\_Fin\_S](https://www.ruby-forum.com/u/Shark_Fin_S)\
**Post date:** [March 4, 2006, 7:56pm UTC](https://www.ruby-forum.com/t/file-column/76691/3 "2006-03-04T19:56:43Z")

</div>

Shark Fin S. wrote:

> Restricting size of an uploaded file, is how is that possible? If I  
> do not want a user to upload a file larger than X bytes, can it  
> easily be done?
> 
> If I also would like restrict the types of files that can be  
> uploaded, how may I do so?

You should be able to write a conditional using rmagick’s image.filesize  
attribute:  
[http://www.simplesystems.org/RMagick/doc/imageattrs.html#filesize](http://www.simplesystems.org/RMagick/doc/imageattrs.html#filesize)

Same goes for the format with the image.format attribute:  
[http://www.simplesystems.org/RMagick/doc/imageattrs.html#format](http://www.simplesystems.org/RMagick/doc/imageattrs.html#format)

---

<div class="post-metadata">

**Author:** ![Shark\_Fin\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@Shark\_Fin\_S](https://www.ruby-forum.com/u/Shark_Fin_S)\
**Post date:** [March 4, 2006, 11:39pm UTC](https://www.ruby-forum.com/t/file-column/76691/4 "2006-03-04T23:39:28Z")

</div>

Matthias, of course you are right. I should have mentioned that any kind  
of  
client side validation also needs a serverside validation. Clientside  
validation is not for securing the app, it is to improve usability and  
responsiveness of the app.

---

<div class="post-metadata">

**Author:** ![Shark\_Fin\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@Shark\_Fin\_S](https://www.ruby-forum.com/u/Shark_Fin_S)\
**Post date:** [March 4, 2006, 10:05pm UTC](https://www.ruby-forum.com/t/file-column/76691/5 "2006-03-04T22:05:35Z")

</div>

Roberto S. wrote:

> Filetype can be restricted with a bit of javascript and regular  
> expression when the Input field of the File upload form changes. This  
> [http://blog.caboo.se/articles/2006/02/23/integrate-rails-modules-with-javascript-objects](http://blog.caboo.se/articles/2006/02/23/integrate-rails-modules-with-javascript-objects)  
> might help you to understand how you need to aproach that. Or if you  
> like flash, you can rely on flashplayer 8 for highly configurable  
> file-upload (with smooth progress indicator), but that wil require a  
> lot of Javascript for the integration.

Very bad idea…dont think you can secure any application with JS  
touching/limiting the input / form etc…any kid could still use its very  
own form to upload files without any of your fuzzy JS and you wouldnt  
have won anything…that might just help as an additional feature but  
is anything but secure…also headerdata can be changed easily, so there  
is no way to prevent someone to use his OWN forms to upload stuff, that  
said, any serious validation can only be done serverside.

This is a general rule and belongs to every kind of userdata, not just  
uploaded images…

Greez

Matthias Oesterle

---

<div class="post-metadata">

**Author:** ![Shark\_Fin\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@Shark\_Fin\_S](https://www.ruby-forum.com/u/Shark_Fin_S)\
**Post date:** [March 5, 2006, 12:45pm UTC](https://www.ruby-forum.com/t/file-column/76691/6 "2006-03-05T12:45:20Z")

</div>

Hi,

a) there is a modification of file\_column from kyle:  
[http://opensvn.csie.org/rails\_file\_column/plugins/file\_column/](http://opensvn.csie.org/rails_file_column/plugins/file_column/)  
have a look at  
[http://opensvn.csie.org/rails\_file\_column/plugins/file\_column/trunk/lib/validations.rb](http://opensvn.csie.org/rails_file_column/plugins/file_column/trunk/lib/validations.rb)  
It validates filesizes and extensions.

b) Sebastian, the founder of file\_column, annouced an update (“with  
lots of goodies”) soon:  
[http://www.kanthak.net/explorations/blog/rails/canada\_on\_rails.html](http://www.kanthak.net/explorations/blog/rails/canada_on_rails.html)

Beate

---

<div class="post-metadata">

**Author:** ![Shark\_Fin\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@Shark\_Fin\_S](https://www.ruby-forum.com/u/Shark_Fin_S)\
**Post date:** [March 5, 2006, 2:05am UTC](https://www.ruby-forum.com/t/file-column/76691/7 "2006-03-05T02:05:22Z")

</div>

Roberto S. wrote:

> Matthias, of course you are right. I should have mentioned that any  
> kind of client side validation also needs a serverside validation.  
> Clientside validation is not for securing the app, it is to improve  
> usability and responsiveness of the app.

Absolutly, Roberto, thats the point: it aids in usability and is a nice  
feature

Anyway back to the topic:

I am also in the same need as the starter and remember that after  
spending just a couple of minutes (30, 40, 50…dont remember) some days  
ago I wasnt able to find any (direct) solution, so I still hope that  
someone could answer that.

Probably one has to spend hours beeing new to RMagick and friends,what I  
definatly will do if its coming to that point, but I was also looking  
for something like image.width /.height and couldnt find any  
solution…this is needed to have a popup sized dynamically to the  
“right” size if I click of one of my thumbnails, as its a big different  
dealing with portrait/landscape imageformats…

Regards

Matthias Oesterle
