File upload -> save outside the rails project


#1

i currently have an app that uploads a file and saves it into the file
system…

the one thing i cannot figure out how to do is save it outside the
project…

for instance…

it currently uploads it to:

~/rails_project/public/upload

i would like it to upload to:

~/public_html/upload

any ideas on how to phrase this?

thanks!


#2

In order for it to be saving where it’s saving, RAILS_ROOT is probably
being specified in there somewhere. Remove that and add the directory
yourself to /home/user/public_html/upload or whatever it may be.


#3

Jack B. wrote:

In order for it to be saving where it’s saving, RAILS_ROOT is probably
being specified in there somewhere. Remove that and add the directory
yourself to /home/user/public_html/upload or whatever it may be.

i did just that… i specified:

~/public_html/upload

and what it does is… creates a directory in the rails project called
“~” and puts the files in it…

very strange…


#4

Jacob Basham wrote:

On Fri, 17 Apr 2009, Sergio R. wrote:

i did just that… i specified:

~/public_html/upload

and what it does is… creates a directory in the rails project called
“~” and puts the files in it…

Did you try expanding the path?
File.expand_path("~/public_html/upload")

jake

What about a softlink??


#5

On Fri, 17 Apr 2009, Sergio R. wrote:

i did just that… i specified:

~/public_html/upload

and what it does is… creates a directory in the rails project called
“~” and puts the files in it…

Did you try expanding the path?
File.expand_path("~/public_html/upload")

jake


#6

Did you try expanding the path?
File.expand_path("~/public_html/upload")

perfect! this works great…

thanks!


#7

Be careful here. Expanding “~” depends on who is running the Rails
code and in production it often is either the user that runs the web
server or another “not real” user. (A good thing for security) So
you want to either put an absolute path OR put a path relative to
RAILS_ROOT if you can ensure that permissions will be OK.

Just remember that this may not work in Production.

Brendon.

On Apr 17, 7:17 am, Sergio R. removed_email_address@domain.invalid


#8

What about a softlink??

the only reason i shy away from a softlink is that i am using
git/capistrano for development… i would rather have my paths well
defined…

thanks!


#9

Just remember that this may not work in Production.

Brendon.

thanks!

i just checked…

here’s how i have this set up…

the app runs as a user, inside that user’s home directory…

the files are saved to that same user’s ~/public_html directory… via a
subdomain:

files.domain.com

so permissions work out correctly…

thanks!