# Image\_tag and files outsite /public directory

**URL:** <https://www.ruby-forum.com/t/image-tag-and-files-outsite-public-directory/110161>\
**Category:** Rails\
**Created:** [July 23, 2007, 9:34pm UTC](https://www.ruby-forum.com/t/image-tag-and-files-outsite-public-directory/110161 "2007-07-23T21:34:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jochen\_kaechelin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@jochen\_kaechelin](https://www.ruby-forum.com/u/jochen_kaechelin)\
**Post date:** [July 23, 2007, 9:34pm UTC](https://www.ruby-forum.com/t/image-tag-and-files-outsite-public-directory/110161/1 "2007-07-23T21:34:45Z")

</div>

I have some image files under

/app  
/uploads  
/images/  
111.jpg

/public  
/images

.  
.

How can I user image\_tag to display the images under  
/uploads/images/…?

Any hints?

–  
Jochen K.  
[gissmoh.de](http://gissmoh.de), [figgfrosch.de](http://figgfrosch.de), [ror-ror.de](http://ror-ror.de)

---

<div class="post-metadata">

**Author:** ![jochen\_kaechelin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@jochen\_kaechelin](https://www.ruby-forum.com/u/jochen_kaechelin)\
**Post date:** [July 23, 2007, 9:39pm UTC](https://www.ruby-forum.com/t/image-tag-and-files-outsite-public-directory/110161/2 "2007-07-23T21:39:04Z")

</div>

jochen kaechelin wrote:

> .  
> .
> 
> How can I user image\_tag to display the images under  
> /uploads/images/…?
> 
> Any hints?

Hi Jochen,  
you can create symlink in public dir that would point to uploads.

–  
Bojan M.  
 → Ruby on Rails and Web D. Blog : [http://source.mihelac.org](http://source.mihelac.org)

---

<div class="post-metadata">

**Author:** ![jochen\_kaechelin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@jochen\_kaechelin](https://www.ruby-forum.com/u/jochen_kaechelin)\
**Post date:** [July 23, 2007, 9:42pm UTC](https://www.ruby-forum.com/t/image-tag-and-files-outsite-public-directory/110161/3 "2007-07-23T21:42:19Z")

</div>

Bojan M. schrieb:

> > 
> 
> Hi Jochen,  
> you can create symlink in public dir that would point to uploads.But

But the files must be protected…when I create a syslink everyone  
is able to access them! Right?

–  
Jochen K.  
[gissmoh.de](http://gissmoh.de), [figgfrosch.de](http://figgfrosch.de), [ror-ror.de](http://ror-ror.de)

---

<div class="post-metadata">

**Author:** ![jochen\_kaechelin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@jochen\_kaechelin](https://www.ruby-forum.com/u/jochen_kaechelin)\
**Post date:** [July 23, 2007, 10:36pm UTC](https://www.ruby-forum.com/t/image-tag-and-files-outsite-public-directory/110161/4 "2007-07-23T22:36:47Z")

</div>

Adam C. schrieb:

> protected from what? In what cases do you want users to be able to  
> view these images?

Only logged in users are able to view the files.

When I store the images under /public/images/111.jpg  
everyone is able to view the images.

But I thing I got a soultion:

send\_file RAILS\_ROOT +  
“/downloads/#{params[:galery\_id]}/#{params[:filename]}”, :type =\>  
“image/jpeg”, :disposition =\> ‘inline’

> > > > ```
> > > > 111.jpg
> > > > 
> > > > ```
> > 
> > –  
> > Jochen K.  
> > [gissmoh.de](http://gissmoh.de), [figgfrosch.de](http://figgfrosch.de), [ror-ror.de](http://ror-ror.de)
> 
> >

–  
Jochen K.  
[gissmoh.de](http://gissmoh.de), [figgfrosch.de](http://figgfrosch.de), [ror-ror.de](http://ror-ror.de)

---

<div class="post-metadata">

**Author:** ![jochen\_kaechelin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@jochen\_kaechelin](https://www.ruby-forum.com/u/jochen_kaechelin)\
**Post date:** [July 23, 2007, 10:16pm UTC](https://www.ruby-forum.com/t/image-tag-and-files-outsite-public-directory/110161/5 "2007-07-23T22:16:29Z")

</div>

protected from what? In what cases do you want users to be able to  
view these images?

Adam

---

<div class="post-metadata">

**Author:** ![jochen\_kaechelin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@jochen\_kaechelin](https://www.ruby-forum.com/u/jochen_kaechelin)\
**Post date:** [July 24, 2007, 8:32am UTC](https://www.ruby-forum.com/t/image-tag-and-files-outsite-public-directory/110161/6 "2007-07-24T08:32:42Z")

</div>

jochen kaechelin wrote:

> But I thing I got a soultion:
> 
> send\_file RAILS\_ROOT +  
> “/downloads/#{params[:galery\_id]}/#{params[:filename]}”, :type =\>  
> “image/jpeg”, :disposition =\> ‘inline’

beware that send\_file keep files in memory until they are downloaded, so  
that means you could get in trouble with big files or many downloads at  
time.

Bojan

---

<div class="post-metadata">

**Author:** ![jochen\_kaechelin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@jochen\_kaechelin](https://www.ruby-forum.com/u/jochen_kaechelin)\
**Post date:** [July 24, 2007, 8:52am UTC](https://www.ruby-forum.com/t/image-tag-and-files-outsite-public-directory/110161/7 "2007-07-24T08:52:58Z")

</div>

You can also use the X-Sendfile header to send non-publicly accessible  
files through the web server (providing that it supports this header),  
without tying up your rails process. You can read more about it here:

[http://john.guen.in/past/2007/4/17/send\_files\_faster\_with\_xsendfile/](http://john.guen.in/past/2007/4/17/send_files_faster_with_xsendfile/)

> **[mod\_proxy\_core got X-Sendfile Support - lighty's life](http://blog.lighttpd.net/articles/2006/07/22/mod_proxy_core-got-x-sendfile-support/)**
>
> As promissed mod\_proxy\_core would combine the features from mod\_proxy and mod\_fastcgi. mod\_proxy gave the balancers, mod\_fastcgi gave its fail-over …

Adam

The following may be of use to you:

> **[mod\_proxy\_core got X-Sendfile Support - lighty's life](http://blog.lighttpd.net/articles/2006/07/22/mod_proxy_core-got-x-sendfile-support/)**
>
> As promissed mod\_proxy\_core would combine the features from mod\_proxy and mod\_fastcgi. mod\_proxy gave the balancers, mod\_fastcgi gave its fail-over …

---

<div class="post-metadata">

**Author:** ![jochen\_kaechelin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@jochen\_kaechelin](https://www.ruby-forum.com/u/jochen_kaechelin)\
**Post date:** [July 24, 2007, 9:17am UTC](https://www.ruby-forum.com/t/image-tag-and-files-outsite-public-directory/110161/8 "2007-07-24T09:17:37Z")

</div>

Adam C. wrote:

> You can also use the X-Sendfile header to send non-publicly accessible  
> files through the web server (providing that it supports this header),  
> without tying up your rails process. You can read more about it here:
> 
> [http://john.guen.in/past/2007/4/17/send\_files\_faster\_with\_xsendfile/](http://john.guen.in/past/2007/4/17/send_files_faster_with_xsendfile/)  
> [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)
> 
> Adam

or create own x-send\_file method that would create symlink with unique  
name and redirect logged user to it. Clear can be done with cronjob.

–  
Bojan M.  
 → Ruby on Rails and Web D. Blog : [http://source.mihelac.org](http://source.mihelac.org)
