# Securing image / static content

**URL:** <https://discuss.rubyonrails.org/t/securing-image-static-content/2105>\
**Category:** rubyonrails-talk\
**Created:** [September 24, 2006, 4:56pm UTC](https://discuss.rubyonrails.org/t/securing-image-static-content/2105 "2006-09-24T16:56:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nasir\_Khan](https://avatars.discourse-cdn.com/v4/letter/n/5daacb/32.png) [@Nasir\_Khan](https://discuss.rubyonrails.org/u/Nasir_Khan)\
**Post date:** [September 24, 2006, 4:56pm UTC](https://discuss.rubyonrails.org/t/securing-image-static-content/2105/1 "2006-09-24T16:56:03Z")

</div>

I have some images under /public/images/ in a RoR application. I am accesing the images from view templates using standard html ![]() tags. Since the images are under a public directory they can be accessed by anyone (not coming through my application).

What is the best way to keep my images accesible only to authorized users? I cannot keep them in a non public dir because ![]() will not work then.

Thanks

---

<div class="post-metadata">

**Author:** ![Luke\_Redpath1](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@Luke\_Redpath1](https://discuss.rubyonrails.org/u/Luke_Redpath1)\
**Post date:** [September 24, 2006, 5:21pm UTC](https://discuss.rubyonrails.org/t/securing-image-static-content/2105/2 "2006-09-24T17:21:38Z")

</div>

Keep the images out of the public dir (say RAILS\_ROOT/assets/images) and then write an ImagesController that will serve up the images by setting the appropriate content-type and using send\_data/Ruby IO.

---

<div class="post-metadata">

**Author:** ![Nasir\_Khan](https://avatars.discourse-cdn.com/v4/letter/n/5daacb/32.png) [@Nasir\_Khan](https://discuss.rubyonrails.org/u/Nasir_Khan)\
**Post date:** [September 24, 2006, 6:09pm UTC](https://discuss.rubyonrails.org/t/securing-image-static-content/2105/3 "2006-09-24T18:09:04Z")

</div>

Thanks for the response. Wouldnt using send\_data be inefficient as the bytes will be read in the server memory first? How can Ruby IO be used?

Thanks

---

<div class="post-metadata">

**Author:** ![Vishnu\_Gopal](https://avatars.discourse-cdn.com/v4/letter/v/b9e5f3/32.png) [@Vishnu\_Gopal](https://discuss.rubyonrails.org/u/Vishnu_Gopal)\
**Post date:** [September 24, 2006, 6:50pm UTC](https://discuss.rubyonrails.org/t/securing-image-static-content/2105/4 "2006-09-24T18:50:40Z")

</div>

Hi, I’d add to what **ljredpath** suggested. Keep your images in an assets folder, but if you use Lighty, an X-Sendfile header will work wonders, as Lighty itself will fetch the file for you. Read more about that here: [http://blog.lighttpd.net/articles/2006/07/02/x-sendfile](http://blog.lighttpd.net/articles/2006/07/02/x-sendfile) (I’m waiting for this too: [http://blog.lighttpd.net/articles/2006/07/22/mod\_proxy\_core-got-x-sendfile-support](http://blog.lighttpd.net/articles/2006/07/22/mod_proxy_core-got-x-sendfile-support) )

This is probably the most “efficient” solution.

Vish
