Hello Rails people, I''m having trouble with basic file uploads with my Rails app. I keep receiving an Errno::EACCES error with the message: Permission denied - /public/images/diary_images/tim_sp.jpg /app/models/diary_image.rb:14:in `uploaded_file='' It''s likely something obvious that I''ve missed that''s the cause and I''m not too familiar with how file permissions work on OS X, which I''ve switched to recently and am developing this on. If anyone could shed any light on the situation it''d be greatly appreciated. Thanks, Matt ------------------------------------- Snippet from the controller: image = DiaryImage.new image.uploaded_file = params[:image_file] image.save! Snippet from the model: def uploaded_file=(incoming_file) @file = incoming_file self.file_name = incoming_file.original_filename self.content_type = incoming_file.content_type File.chmod(0600, incoming_file.local_path) if !incoming_file.local_path.nil? && File.exist? (incoming_file.local_path) FileUtils.copy(incoming_file.local_path, "#{RAILS_ROOT}/ public/images/diary_images/#{self.file_name}") else File.open("#{RAILS_ROOT}/public/images/diary_images/# {self.file_name}", "wb") do |f| f.write(@file.read) end end end
On 6/27/05, list action <listaction-FXsoPwVLZSKdyyGsB3R/UQ@public.gmane.org> wrote:> Hello Rails people, > > I''m having trouble with basic file uploads with my Rails app. I keep > receiving an Errno::EACCES error with the message: > > Permission denied - /public/images/diary_images/tim_sp.jpg > > /app/models/diary_image.rb:14:in `uploaded_file='' > > > It''s likely something obvious that I''ve missed that''s the cause and > I''m not too familiar with how file permissions work on OS X, which > I''ve switched to recently and am developing this on. If anyone could > shed any light on the situation it''d be greatly appreciated. > > Thanks, > > MattI think you''ll need to make sure that your webserver has write access to the directory in whch you are trying to write the file. This can be done a few ways... the easiest (and perhaps most insecure) would be to simply make that directory world writeable. Alternatively, you can change the "group" of the directory so it belongs to the same group as the webserver: $> chown username:www diary_images/ $> chmod g+w diary_images/ Matt
On 27 Jun 2005, at 15:44, Belorion wrote:> On 6/27/05, list action <listaction-FXsoPwVLZSKdyyGsB3R/UQ@public.gmane.org> wrote: > >> Hello Rails people, >> >> I''m having trouble with basic file uploads with my Rails app. I keep >> receiving an Errno::EACCES error with the message: >> >> Permission denied - /public/images/diary_images/tim_sp.jpg >> >> /app/models/diary_image.rb:14:in `uploaded_file='' >> >> >> It''s likely something obvious that I''ve missed that''s the cause and >> I''m not too familiar with how file permissions work on OS X, which >> I''ve switched to recently and am developing this on. If anyone could >> shed any light on the situation it''d be greatly appreciated. >> >> Thanks, >> >> Matt >> > > > I think you''ll need to make sure that your webserver has write access > to the directory in whch you are trying to write the file. This can > be done a few ways... the easiest (and perhaps most insecure) would be > to simply make that directory world writeable. Alternatively, you can > change the "group" of the directory so it belongs to the same group as > the webserver: > > $> chown username:www diary_images/ > $> chmod g+w diary_images/ > > MattThanks so much, that did the trick!