[Mongrel] Mongrel and umask for uploaded files

Mike Garey random49k at gmail.com
Tue Sep 5 17:32:41 EDT 2006

So any files that are uploaded through my form are getting the following mode:


I need them to have:


I've tried setting the umask in a script file called set_umask.rb as follows:


and then starting mongrel using:

mongrel_rails start -m config/mime.types -S set_umask.rb

but it doesn't seem to change the mode that the files are created
with..  I've also tried putting "File.umask(022)' inside
environment.rb but that doesn't make a difference.

To handle uploads, I have a resource model which does the following in
the before_create filter:

  def before_create
    return FileUtils.copy( @uploaded_file.local_path,
self.path_to_file) if @uploaded_file.instance_of?(Tempfile)
    # else
    File.open(self.path_to_file, "w") { |f| f.write(@uploaded_file.read) }

If anyone has any other hints for how to change the umask, please let
me know, this is driving me crazy!  Thanks,


More information about the Mongrel-users mailing list