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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Urban, i am relatively new to Rails, so i may be wrong, but i had the same problem recently and resorted to putting smaller images in the public directory, which are displayed. The original (larger) images cannot be displayed in my 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 with files outside of the app''s directory structure and it is vital for your app to do so, i would try to put the images outside and copy them to a directory beneath the public directory whenever you have to display them (and delete 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 all. And last (but i read not much good about the method): You could put the images as blobs in the db. Jochen 2007/6/11, urbanf <urban.faubion-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org >:> > > 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. > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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="" /> Cam On Jun 12, 7:47 am, "Jochen Bilagher" <jbila...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Hi Urban, > > i am relatively new to Rails, so i may be wrong, but i had the same problem > recently and resorted to putting smaller images in the public directory, > which are displayed. The original (larger) images cannot be displayed in my > 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 with > files outside of the app''s directory structure and it is vital for your app > to do so, i would try to put the images outside and copy them to a directory > beneath the public directory whenever you have to display them (and delete > 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 all. > And last (but i read not much good about the method): You could put the > images as blobs in the db. > > Jochen > > 2007/6/11, urbanf <urban.faub...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org >: > > > > > 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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Urban, 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 send_data(some_variable_holding_the_image_data, :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 Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org On Jun 12, 2007, at 12:17 AM, cammo wrote:> > 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="" /> > > Cam > > On Jun 12, 7:47 am, "Jochen Bilagher" <jbila...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> Hi Urban, >> >> i am relatively new to Rails, so i may be wrong, but i had the >> same problem >> recently and resorted to putting smaller images in the public >> directory, >> which are displayed. The original (larger) images cannot be >> displayed in my >> 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 with >> files outside of the app''s directory structure and it is vital for >> your app >> to do so, i would try to put the images outside and copy them to a >> directory >> beneath the public directory whenever you have to display them >> (and delete >> 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 all. >> And last (but i read not much good about the method): You could >> put the >> images as blobs in the db. >> >> Jochen >> >> 2007/6/11, urbanf <urban.faub...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org >: >> >>> 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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. UF On Jun 12, 6:37 am, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> Urban, > > 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 > > send_data(some_variable_holding_the_image_data, > :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 > > Rob Biedenharn http://agileconsultingllc.com > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org > > On Jun 12, 2007, at 12:17 AM, cammo wrote: > > > > > 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="" /> > > > Cam > > > On Jun 12, 7:47 am, "Jochen Bilagher" <jbila...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> Hi Urban, > > >> i am relatively new to Rails, so i may be wrong, but i had the > >> same problem > >> recently and resorted to putting smaller images in the public > >> directory, > >> which are displayed. The original (larger) images cannot be > >> displayed in my > >> 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 with > >> files outside of the app''s directory structure and it is vital for > >> your app > >> to do so, i would try to put the images outside and copy them to a > >> directory > >> beneath the public directory whenever you have to display them > >> (and delete > >> 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 all. > >> And last (but i read not much good about the method): You could > >> put the > >> images as blobs in the db. > > >> Jochen > > >> 2007/6/11, urbanf <urban.faub...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org >: > > >>> 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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---