Paperclip Errno::EACCES (Permission denied - /system) - ruby-on-rails

My production environment is : ruby 1.9.2-p320 , rails 3.2.7, paperclip 3.1.4, mysql, Ubuntu 8.10 x86 64bit.
I have a Errno:EACCES Permission denied /system error when i try to upload a file with paperclip. Useless to say that locally this doesn't happen.
I checked the public directory permissions and it's 775, the public/system permission is 777 as well as all it's inner directory. The tmp directory permission is : 775 too.
Moreover the user used to deploy the application is www-data:root
The model's attachment is set like this :
has_attached_file :fichier,
:path => "/system/:attachment/:id/:style/:filename",
:url => "/system/:attachment/:id/:style/:filename"
I can't find out why i get this error. Anyone has got an idea ?
Thanks

Your code DOES NOT try to save the uploaded file in:
/path/to/app/public/system/:attachment/:id/:style/:filename
but in:
/system/:attachment/:id/:style/:filename
Try this instead:
has_attached_file :fichier,
:path => ":rails_root/public/system/:attachment/:id/:style/:filename",
:url => "/system/:attachment/:id/:style/:filename"

Related

Rails 4.2.0 - Errno::EACCES (Permission denied # dir_s_mkdir - /files)

In rails 4.2.0, I am using paperclip for file uploads. But it is throwing an error like Errno::EACCES (Permission denied # dir_s_mkdir - /files), how can I fix this issue?
When I run gem list paperclip, I got the list like below
paperclip (4.3.0, 4.2.2, 4.2.0, 2.4.5)
In controller, I have tried 2 ways, one is #file = Asset.new(:document=>params[:asset][:document]) and the other way is
#file = Asset.new(user_params)
def user_params
params.require(:asset).permit(:document)
end
In model,
attr_accessible :status, :document_file_name, :document_content_type, :document_file_size
attr_accessible :document
has_attached_file :document,
:url => '/files/:assetable_id/:basename.:extension',
:path => "/files/:assetable_id/:basename.:extension",
:storage => :filesystem
How can I solve this permission denied issue?
Change your path to the following (using :rails_root):
:path => ":rails_root/files/:assetable_id/:basename.:extension"
rails_root will give you the path to your app.
To create Directory on local drive here is the running code-
To do so I was executing-
Dir.mkdir(Rails.root+ '/' + 'export')
But getting error as-
Errno::EACCES: Permission denied # dir_s_mkdir - /Main_File
I know what was the reason, it was looking for Super User ($ sudo) permission but we can't provide machine password each time.
Following worked for me as required-
Dir.mkdir(File.join(Dir.home, ".foo"), 0700) #=> 0
To create and store the path in a variable-
main_file = File.exist?( File.join(Dir.home, "Main_File") ) ? File.join(Dir.home, "/Main_File") : Dir.mkdir( File.join(Dir.home, "Main_File") )
Above will create file if doesn't exist
If it exist will access that and store in variable main_file.
Thanks for this link!
Hope will work for you !

Paperclip attachments gone after upgrade to Rails 4.0

I have a capistrano deployment on my server at:
/srv/www/pitot.io/public_html/pitot/pitot-production
Where within this folder, I have the following:
current releases repo revisions.log shared
My previous installations paperclip files were stored like this, and still exist there:
/srv/www/pitot.io/public_html/pitot/pitot-production/shared/system/airlines/logos/000/001/199/thumb/thumb_asianspirit-b.gif
Now, I have an issue here. In my Airline model, I have the following line:
has_attached_file :logo, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png",
:path => ":rails_root/public/system/:class/:attachment/:id/:style/:filename",
:url => "/system/:class/:attachment/:id/:style/:filename"
But the images aren't appearing anymore. In my migration, I changed to nginx and rsynced the folders to the new server, maintaining symbolic links. Is there some symbolic link somewhere that I'm missing?
The issue was that I had upgraded capistrano to the newest version (3.2.1) without noticing that the new version no longer automatically makes a symbolic link between public/system and ../shared/public/system. I have changed this, and it is now correct. It is done by uncommenting the line:
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
in deploy.rb

Rails Paperclip Processor: shell command failing

I've got a problem with a custom paperclip processor within my rails app. I upload a soundfile and the processor creates an waveform image via a shell command (provided by this gem)
I'm running RoR 3.2.7 / Ruby 1.9.3 on Ubuntu 12.04 (production environment). My model with paperclip attachment looks like the following:
# encoding: utf-8
class Track < ActiveRecord::Base
has_attached_file :original_file,
:styles => { :waveform_image => { :waveform => true } },
:processors => [:sound_processor],
:storage => :s3,
:s3_credentials => "#{Rails.root.to_s}/config/s3.yml",
:url => ":s3_eu_url",
:path => "sounds/:id/:five_digit_id_:basename_:style.:extension"
end
The corresponding Paperclip Processor:
class Paperclip::SoundProcessor < Paperclip::Processor
def initialize file, options = {}, attachment = nil
# cut for brevity
end
def make
src = #file
dst = Tempfile.new([#basename, #current_format])
dst.binmode
if #waveform
cmd = "waveform #{File.expand_path(src.path)} #{File.expand_path(dst.path)}"
Paperclip.log(cmd)
out = `#{cmd}`
dst = File.open "#{File.expand_path(dst.path)}"
end
dst
end
end
When the command
waveform #{File.expand_path(src.path)} #{File.expand_path(dst.path)}
is getting executed on the production machine (Ubuntu 12.04), the following error comes up:
/usr/bin/env: ruby: No such file or directory
However the usr/bin/env is a file instead of an directory. Since there is no ruby executable, how can I pass the right location when executing the shell command?
PS: On my development machine (OSX), on usr/bin/env is a copy of my rails app directory. It's working like a charm in development. I appreciate your help!
The error message is indicating that the ruby executable was not found. It is not related to the code that you have included in the question as of now.
The error is coming from the script file that includes the waveform #{File.expand_path(src.path)} #{File.expand_path(dst.path)} line.
Check out these answers to the issue:
- https://stackoverflow.com/a/6126419/429758
- https://stackoverflow.com/a/5241638/429758
- https://stackoverflow.com/a/5241593/429758
- https://stackoverflow.com/a/1064319/429758
They should give you some idea as to why the ruby executable is not being found on your production environment.

Image file is not recognized by the 'identify' command. (heroku)

I'm trying to have Paperclip working with Heroku and Amazon S3.
Everything works fine on localhost (mac OS and Amazon), but when I'm deploying to heroku and trying the feature, I have this error :
2 errors prohibited this area from being saved:
Asset /tmp/paris20121005-2-2cwxgx.jpg is not recognized by the 'identify' command.
Asset /tmp/paris20121005-2-2cwxgx.jpg is not recognized by the 'identify' command.
It works when I remove the :styles => { } option in my model, but the file isn't processed (I need different image sizes).
I also have the rmagick gem in my gemfile.
Here is my gemfile (only the paperclip part) :
gem "paperclip"
gem "rmagick", :require => 'RMagick'
gem 'aws-sdk', '~> 1.3.4'
I don't have Paperclip.options[:command_path] set in my environment.rb or production.rb so no problem on this side.
Here is my model :
class Area < ActiveRecord::Base
require 'RMagick'
has_attached_file :asset, :styles => { :medium => "300x300>", :thumb => "180x190>" },
:storage => :s3,
:s3_credentials => "#{::Rails.root.to_s}/config/s3.yml",
:url => :s3_domain_url.to_s,
:path => "/:style/:id/:filename"
end
Any clue on that ? I've crawled every topics about it and nothing seems to work...
Thanks
Apparently the new update to Cocaine gem (0.4.0) breaks the file names for Paperclip and ImageMagick. try rolling back to the previous version (0.3.2), it worked for me.
See here:
https://github.com/thoughtbot/paperclip/issues/1038
PS I believe RMagick is no longer needed on Heroku, works fine for me without it

Reading file attached with paperclip -- No such file or directory

Why am I getting no such file or directory when I use a symbol in my path? Paperclip shows :rails_root/public/system/:class/:attachment/:id_partition/:style/:filename as the default path. The file is in public/system/attachments/email.txt, but I want to be able to add a file with any name.
has_attached_file :email,
:url => "public/system/attachments/:filename",
:path => "public/system/attachments/:filename"
def read_original_header
#original_email = File.read("public/system/attachments/:filename")
end
No such file or directory - public/system/attachments/:filename
Your issue is that the 'symbol' interpolation is a Paperclip convention, this convention is not shared by the standard Ruby File class.

Resources