Shruthi R
Shruthi R

Reputation: 1923

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?

Upvotes: 1

Views: 2747

Answers (2)

S.Yadav
S.Yadav

Reputation: 4509

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 !

Upvotes: -1

K M Rakibul Islam
K M Rakibul Islam

Reputation: 34338

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.

Upvotes: 3

Related Questions