Forum: Ruby on Rails Linking to images outside public folder

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Cc69b3eb7375b07e059d199f25f720c2?d=identicon&s=25 urbanf (Guest)
on 2007-06-11 20:36
(Received via mailing list)
I have a project where I need to show images (.jpg's) in the browser
that are outside my projects "public" directory. I'm developing on a
Mac and I've tried using an absolute path "/Users/my_name/Desktop/
image.jpg". I can use this technique to read the contents of .txt
files and send it as a string to the browser but I can't get images to
display. Do I need to use send_file or send_data to get the images to
display? Any help would be great. Thanks.
7111f8aecd54480d87c3fc42822706f0?d=identicon&s=25 Jochen Bilagher (Guest)
on 2007-06-11 23:47
(Received via mailing list)
Hi Urban,

i am relatively new to Rails, so i may be wrong, but i had the same
recently and resorted to putting smaller images in the public directory,
which are displayed. The original (larger) images cannot be displayed in
app, but they can be downloaded. For downloading i used send_file.
If i am right in my assumption that there is no way to use image_tag
files outside of the app's directory structure and it is vital for your
to do so, i would try to put the images outside and copy them to a
beneath the public directory whenever you have to display them (and
them afterwards). Surely, that would not improve performance...
Another thing i read of to solve the problem of having files in a public
directory, but not wanting people to access them freely: Put them in
directories and make those directories' names unguessable - this way you
will allow people to access single images, but they cannot access them
And last (but i read not much good about the method): You could put the
images as blobs in the db.


2007/6/11, urbanf < >:
B01fdd12039d82427a4af02360ef5571?d=identicon&s=25 cammo (Guest)
on 2007-06-12 06:18
(Received via mailing list)
if your using the image_tag helper I thin that automatically points to
your public directory. Try just using an old skool <img src="/
Users....." alt="" />

Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2007-06-12 15:38
(Received via mailing list)

The browser can only request things by a URI and that will be served
by the web listener if it's a resource (file) under the document
root.  Typically, this is the public/ directory.  Other resources
might be available to a request being serviced by your Rails
application.  You could return the image *data* as a result of the
request using either of the methods you mentioned:

     send_file( '/Users/my_name/Desktop/image.jpg',
                :disposition => 'inline',
                :type => 'image/jpeg',
                :stream => false,
                :filename => 'image.jpg' )

# The :filename is what will be suggested if the browser offers to
save the image

               :disposition => 'inline',
               :type => 'image/png',
               :filename => "on-the-fly.png")

The URI in the <img src='THIS'> needs to be routed to a controller
action of your that finds or builds the image data and uses send_* to
give it to the browser.


Rob Biedenharn
Cc69b3eb7375b07e059d199f25f720c2?d=identicon&s=25 urbanf (Guest)
on 2007-06-12 17:21
(Received via mailing list)
Thanks for the help everyone. I ended up using "send_file" as Rob
showed above to get my project to display images in the browser that
are outside my Rails project root.


On Jun 12, 6:37 am, Rob Biedenharn <>
This topic is locked and can not be replied to.