| ||||
A blog about Ruby, Rails and other Tech. Mostly.Back to blog
There is a wonderful plugin for Rails called file column that makes it easy to handle uploading files, image files in particular. It's really good, but I have been persistently having a problem that the uploaded files are coming in with permission 600, so they cannot be read by the web server when you try to access them. The problem does not happen every time. Setting the umask in environment.rb (as has been suggested) does not help. Eventually I fixed it by hacking lib/file_column.rb: (this section starts at line 321)
def move_from(local_dir, just_uploaded)
# create a directory named after the primary key, first
FileUtils.mkdir(@dir) unless File.exists?(@dir)
# move the temporary files over
FileUtils.cp Dir.glob(File.join(local_dir, "*")), @dir
@just_uploaded = just_uploaded
# remove all old files in the directory
FileUtils.rm(Dir.glob(File.join(@dir, "*")).reject! {
|e| File.exists?(File.join(local_dir, File.basename(e)))
})
# set permissions - added by sds because of weird perms problems
FileUtils.chmod 0664, Dir.glob(File.join(@dir, "*"))
end
Fixed. Back to blog |