# Problem with file upload

**URL:** <https://www.ruby-forum.com/t/problem-with-file-upload/106773>\
**Category:** Rails\
**Created:** [June 13, 2007, 11:18pm UTC](https://www.ruby-forum.com/t/problem-with-file-upload/106773 "2007-06-13T23:18:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [June 13, 2007, 11:18pm UTC](https://www.ruby-forum.com/t/problem-with-file-upload/106773/1 "2007-06-13T23:18:40Z")

</div>

I have a simple app that allows users to upload image files to the web  
server. It works fine on my laptop with Webrick, when I deploy to the  
web server it also works fine with webrick. However, when I try to  
connect via Apache, the files get uploaded to the /tmp directory, but  
the never make it to the correct directory within the application (/  
public/images/photos). I am sure that this is some permissions  
problem with the Apache user (Apache runs as user:nobody,  
group:nobody) but it appears that all of the correct permissions are  
in place. Here are the permissions on the photos directory:

drwxrwxr-x 2 jzw nobody 4096 Jun 13 15:18 photos/

And here is the error:

Errno::EACCES (Permission denied - public/images/photos/28-full.jpg):  
/home/jzw/public\_html/my\_app/app/models/photo.rb:261:in  
`initialize' /home/jzw/public_html/my_app/app/models/photo.rb:261:in`open’  
/home/jzw/public\_html/my\_app/app/models/photo.rb:261:in  
`save_full' /home/jzw/public_html/my_app/app/models/photo.rb:250:in`save\_file’  
/vendor/rails/activerecord/lib/active\_record/callbacks.rb:333:in  
`send' /vendor/rails/activerecord/lib/active_record/callbacks.rb:333:in`callback’  
/vendor/rails/activerecord/lib/active\_record/callbacks.rb:330:in  
`each' /vendor/rails/activerecord/lib/active_record/callbacks.rb:330:in`callback’  
/vendor/rails/activerecord/lib/active\_record/callbacks.rb:243:in  
`create_or_update' /vendor/rails/activerecord/lib/active_record/base.rb:1548:in`save\_without\_validation’  
/vendor/rails/activerecord/lib/active\_record/validations.rb:752:in  
`save_without_transactions' /vendor/rails/activerecord/lib/active_record/transactions.rb: 129:in`save’  
/vendor/rails/activerecord/lib/active\_record/connection\_adapters/  
abstract/database\_statements.rb:59:in `transaction’  
/home/jzw/public\_html/my\_app/public/dispatch.fcgi:34

Errno::EACCES (Permission denied - public/images/photos/28-full.jpg):  
/home/jzw/public\_html/my\_app/app/models/photo.rb:261:in  
`initialize' /home/jzw/public_html/my_app/app/models/photo.rb:261:in`open’  
/home/jzw/public\_html/my\_app/app/models/photo.rb:261:in  
`save_full' /home/jzw/public_html/my_app/app/models/photo.rb:250:in`save\_file’  
/vendor/rails/activerecord/lib/active\_record/callbacks.rb:333:in  
`send' /vendor/rails/activerecord/lib/active_record/callbacks.rb:333:in`callback’  
/vendor/rails/activerecord/lib/active\_record/callbacks.rb:330:in  
`each' /vendor/rails/activerecord/lib/active_record/callbacks.rb:330:in`callback’  
/vendor/rails/activerecord/lib/active\_record/callbacks.rb:243:in  
`create_or_update' /vendor/rails/activerecord/lib/active_record/base.rb:1548:in`save\_without\_validation’  
/vendor/rails/activerecord/lib/active\_record/validations.rb:752:in  
`save_without_transactions' /vendor/rails/activerecord/lib/active_record/transactions.rb: 129:in`save’  
/vendor/rails/activerecord/lib/active\_record/connection\_adapters/  
abstract/database\_statements.rb:59:in `transaction' /vendor/rails/activerecord/lib/active_record/transactions.rb:95:in`transaction’  
/vendor/rails/activerecord/lib/active\_record/transactions.rb:  
121:in `transaction' /vendor/rails/activerecord/lib/active_record/transactions.rb: 129:in`save’  
/home/jzw/public\_html/my\_app/app/controllers/admin/  
photos\_controller.rb:79:in `new_or_edit' /home/jzw/public_html/my_app/app/controllers/admin/ photos_controller.rb:22:in`new’  
/vendor/rails/actionpack/lib/action\_controller/base.rb:1097:in  
`send' /vendor/rails/actionpack/lib/action_controller/base.rb:1097:in`perform\_action\_without\_filters’  
/vendor/rails/actionpack/lib/action\_controller/filters.rb:723:in  
`call_filters' /vendor/rails/actionpack/lib/action_controller/filters.rb:713:in`call\_filters’  
/vendor/rails/actionpack/lib/action\_controller/filters.rb:661:in  
`call' /vendor/rails/actionpack/lib/action_controller/filters.rb:661:in`proxy\_before\_and\_after\_filter’  
/vendor/rails/actionpack/lib/action\_controller/filters.rb:482:in  
`call' /vendor/rails/actionpack/lib/action_controller/filters.rb:482:in`call’  
/vendor/rails/actionpack/lib/action\_controller/filters.rb:711:in  
`call_filters' /vendor/rails/actionpack/lib/action_controller/filters.rb:680:in`perform\_action\_without\_benchmark’  
/vendor/rails/actionpack/lib/action\_controller/benchmarking.rb:  
66:in `perform_action_without_rescue' /usr/lib/ruby/1.8/benchmark.rb:293:in`measure’  
/vendor/rails/actionpack/lib/action\_controller/benchmarking.rb:  
66:in `perform_action_without_rescue' /vendor/rails/actionpack/lib/action_controller/rescue.rb:83:in`perform\_action’

Any help is greatly appreciated.

---

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [June 29, 2007, 12:53am UTC](https://www.ruby-forum.com/t/problem-with-file-upload/106773/2 "2007-06-29T00:53:01Z")

</div>

It has been a couple of weeks and I still have not figured this  
out… Surely someone out there has an idea…

---

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [June 29, 2007, 8:51am UTC](https://www.ruby-forum.com/t/problem-with-file-upload/106773/3 "2007-06-29T08:51:42Z")

</div>

I’m puzzled why Apache’s should be the relevant user as it doesn’t  
execute Rails code. But to test further if it is indeed a permissions  
issue, try either setting permissions to 777 (or 766) on that  
directory, or making nobody the owner (not just the group).  
Personally, I wouldn’t try to give permissions to nobody as the whole  
point of that account is that it has none (which is an issue that  
crops up for Web DAV fairly frequently, see for example \<http://  
[www.lyra.org/pipermail/dav-dev/2001-August/002676.html](http://www.lyra.org/pipermail/dav-dev/2001-August/002676.html)\>). But  
creating world writeable directories also has issues. So perhaps run  
apache as www group www and manage it as a real user – if that is  
indeed the problem.
