# File Column Directory Add another layer

**URL:** <https://www.ruby-forum.com/t/file-column-directory-add-another-layer/50758>\
**Category:** Rails\
**Created:** [December 20, 2005, 10:36pm UTC](https://www.ruby-forum.com/t/file-column-directory-add-another-layer/50758 "2005-12-20T22:36:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dukael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c77e96/32.png) [@dukael](https://www.ruby-forum.com/u/dukael)\
**Post date:** [December 20, 2005, 10:36pm UTC](https://www.ruby-forum.com/t/file-column-directory-add-another-layer/50758/1 "2005-12-20T22:36:35Z")

</div>

Quick Question. I understand how to change the default path to  
something other than public but what if I wanted to add another  
directory into the equation. I want to upload an image into the  
following structure:

/public/image/userid/imageid/test.gif

So basically I want to look up the userid in my users table and put  
all the images for that user in the same directory. So i have a one  
more level of separation. The reason being that we want to have a  
bandwidth cap put on download for our app. We are doing this via  
virtual’s set on the server however with all the virtuals pointing to  
the same place it is possible for a malicious user to find out  
another virtuals name and use that as a workaround to their bandwidth  
constraint. Is it possible? has anyone else tried this?

Thanks

Andrew

---

<div class="post-metadata">

**Author:** ![dukael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c77e96/32.png) [@dukael](https://www.ruby-forum.com/u/dukael)\
**Post date:** [December 21, 2005, 3:04am UTC](https://www.ruby-forum.com/t/file-column-directory-add-another-layer/50758/2 "2005-12-21T03:04:58Z")

</div>

This certainly isn’t a concise answer to your query, but I needed to do  
several things with uploaded images, beyond what file\_column provided.  
I’m  
just gonna paste stuff right out of my Registrant model rather than try  
to  
figure out how to make it generic for you…

def save\_image(image\_to\_crop, crop\_params)  
img\_base = RAILS\_ROOT + “/public/images/registrants/”  
img\_filename = self.id.to\_s + “.jpg”  
y, x, w, h = crop\_params.split(’,’)

```
logger.info("Trying to open " + image_to_crop)

img = ::Magick::ImageList.new(image_to_crop)

img.crop!(x.to_i, y.to_i, w.to_i, h.to_i)
img.resize!(120, 120)
color_thumb = img.resize(32, 32)
grey_img = img.quantize(256, ::Magick::GRAYColorspace)
img.write(img_base + img_filename)
grey_img.write(img_base + 'greyscale/' + img_filename)
color_thumb.write(img_base + 'thumbnail/' + img_filename)

```

end

image\_to\_crop comes from the view where the file\_column field  
originated:

save\_image is called from the controller.

Hopefully you’ll see something there that will help you with your issue.

David R.

---

<div class="post-metadata">

**Author:** ![dukael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c77e96/32.png) [@dukael](https://www.ruby-forum.com/u/dukael)\
**Post date:** [December 21, 2005, 3:59am UTC](https://www.ruby-forum.com/t/file-column-directory-add-another-layer/50758/3 "2005-12-21T03:59:03Z")

</div>

With the trunk version of file\_column, you can:

class Model #…  
file\_column :field, :store\_dir = \> :dynamic\_dir

def dynamic\_dir  
File.join(field\_options[:root\_path], “model\_name”,  
Digest::SHA1.hexdigest(User.current\_user.hash)[0…9], “field\_name”)  
#…

Have you looked into lighty’s protected downloads feature? That might  
be a better solution.

---

<div class="post-metadata">

**Author:** ![dukael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c77e96/32.png) [@dukael](https://www.ruby-forum.com/u/dukael)\
**Post date:** [December 21, 2005, 3:46pm UTC](https://www.ruby-forum.com/t/file-column-directory-add-another-layer/50758/4 "2005-12-21T15:46:01Z")

</div>

Well I have not looked into it yet. But the trunk version of  
file\_column will allow me to do what I want to do, while lighty does  
not support the throttling that we are looking to do. We are still  
trying to find a webserver that will and that also supports rails.

I’ll have to go and grab the trunk version of file column.

Andrew
