Topic: Can I place files (images, videos, etc.) outside the public dir?

I just want to know any possibilities regarding this one.

I actually have important files that are stored on public folder and I would like to place it outside the public folder (probably on a folder on the root dir). This files consists of images, videos, audios and texts(in swf format).

I would like to ask if this is possible and any suggestions or insights might also help.

Thank you.

Re: Can I place files (images, videos, etc.) outside the public dir?

Yes you can, and then you'll need a controller that provides access to them, along with any permissions checking that you might want to perform.

I blogged about doing this a while ago, it's Rails 2.x and Paperclip based but the basic ideas are generic enough to get you started.

Rob Anderton
TheWebFellas

Re: Can I place files (images, videos, etc.) outside the public dir?

Hi,
asset_host will enable you to place files wherever you want, you can read more here http://apidock.com/rails/ActionView/Hel … tTagHelper

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: Can I place files (images, videos, etc.) outside the public dir?

hi! thanks for the reply..

I actually tried this earlier and was able to do what I want using send_file.. Actually the scenario would be to display the files normally as if they were in public. So my code was something like this (just a pseudo code only):

for controller:

def show_file_by_send_file
  send_file "#{RAILS_ROOT}params[:filepath]", 
                     :type => [// I did some logic for determining the type of object to present], 
                     :disposition => "inline"
end

and in my views (let say an image):

<%= image_tag url_for(:controller => 'controller_name', :action =>'show_file_by_send') %>

The said image was shown successfully, but the problem is, when a user views the page source and see or know the URL generated by URL_FOR, the file still shows up and still accessible from the public for downloading/saving locally. Doing so does not resolve my problem.

What I actually wanted to do is let the site display this files but disallow users from seing my files when accessing it directly. Is this possible to do via RoR code?

Re: Can I place files (images, videos, etc.) outside the public dir?

Once an image is viewable you can do what you want with it! The web is public! If you want to protect something then don't put it on the web
I assume that you are trying to protect copyright assets.
It's impossible to stop someone from copying them but you can watermark documents. This is not an RoR specific issue and there are lots of resources on this subject if you google copyright images you'll see how others attempt this.

You could/should place these assets in a restricted area to allow only those people that you give access to, to see them!

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: Can I place files (images, videos, etc.) outside the public dir?

thanks for the reply.. that's what I thought so too. ( and that is what my client could not understand... sad )

Well, I'm just trying to make sure if there is something I can do to somehow protect those files, either ROR or server side (I mean at least basic ways to protect them)... That's why i'm asking for insights.

Thanks for the time!

Re: Can I place files (images, videos, etc.) outside the public dir?

If you want to be able to use them without the use of any third party plug-in.  Though you would need a separate access controller to be able to use them from a different folder.

I am not quite sure though if it would require special permissions from the core program.

Maybe you could provide as some feedback if you are able to plug it in properly.

Last edited by anthonyc (2011-05-30 22:48:59)