# File.chown

**URL:** <https://www.ruby-forum.com/t/file-chown/119893>\
**Category:** Rails\
**Created:** [November 12, 2007, 12:50am UTC](https://www.ruby-forum.com/t/file-chown/119893 "2007-11-12T00:50:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![doug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dbc845/32.png) [@doug](https://www.ruby-forum.com/u/doug)\
**Post date:** [November 12, 2007, 12:50am UTC](https://www.ruby-forum.com/t/file-chown/119893/1 "2007-11-12T00:50:47Z")

</div>

I have written a helper to upload a file using the http protocol.  
It’s only two lines long; and, for the most part, it works just fine.  
However, when the uploaded file is written, it has root as the owner  
and group. I would really like it to have a different owner and  
group. It would seem that that would be almost trivial. Since the  
uploaded file is written with root as the owner and group, I concluded  
that my helper method must be running as root. So, I thought I would  
just add a third line of code to my helper which would call File.chown  
to change the ownership and group on the uploaded file. It doesn’t  
seem to work. No complaints anywhere, it just doesn’t work. Can  
anyone suggest what I might do to get this to work, i.e., to change  
the ownership and group on the uploaded file? Here’s my helper  
method:

def httpUpload(file2upload,saveAs)  
directoryPath=’/tmp/’  
File.open(directoryPath+saveAs,‘wb’){|f|  
f.write(file2upload.read)}  
File.chown(500,100,directoryPath+saveAs)  
end

Thanks for any input.

```
 ... doug
```
