# File upload -\> save outside the rails project

**URL:** <https://www.ruby-forum.com/t/file-upload-save-outside-the-rails-project/165741>\
**Category:** Rails\
**Created:** [April 16, 2009, 10:54pm UTC](https://www.ruby-forum.com/t/file-upload-save-outside-the-rails-project/165741 "2009-04-16T22:54:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [April 16, 2009, 10:54pm UTC](https://www.ruby-forum.com/t/file-upload-save-outside-the-rails-project/165741/1 "2009-04-16T22:54:52Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [April 16, 2009, 11:07pm UTC](https://www.ruby-forum.com/t/file-upload-save-outside-the-rails-project/165741/2 "2009-04-16T23:07:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [April 17, 2009, 2:26pm UTC](https://www.ruby-forum.com/t/file-upload-save-outside-the-rails-project/165741/3 "2009-04-17T14:26:19Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [April 17, 2009, 4:14pm UTC](https://www.ruby-forum.com/t/file-upload-save-outside-the-rails-project/165741/4 "2009-04-17T16:14:41Z")

</div>

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??

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [April 17, 2009, 3:19pm UTC](https://www.ruby-forum.com/t/file-upload-save-outside-the-rails-project/165741/5 "2009-04-17T15:19:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [April 17, 2009, 4:17pm UTC](https://www.ruby-forum.com/t/file-upload-save-outside-the-rails-project/165741/6 "2009-04-17T16:17:57Z")

</div>

> Did you try expanding the path?  
> File.expand\_path("~/public\_html/upload")

perfect! this works great…

thanks!

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [April 17, 2009, 4:28pm UTC](https://www.ruby-forum.com/t/file-upload-save-outside-the-rails-project/165741/7 "2009-04-17T16:28:43Z")

</div>

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](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [April 17, 2009, 4:18pm UTC](https://www.ruby-forum.com/t/file-upload-save-outside-the-rails-project/165741/8 "2009-04-17T16:18:51Z")

</div>

> 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!

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [April 17, 2009, 4:35pm UTC](https://www.ruby-forum.com/t/file-upload-save-outside-the-rails-project/165741/9 "2009-04-17T16:35:16Z")

</div>

> 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](http://files.domain.com)

…

so permissions work out correctly…

thanks!
