Rails - Errno::EACCES (Permission denied) when upl

2019-02-20 03:04发布

问题:

I have:

  • heroku
  • rails 3
  • carrierwave

On localhost uploading works fine. But it doesnt work on heroku. My logs are:

Completed 500 Internal Server Error in 13ms
Errno::EACCES (Permission denied - /app/public/uploads/tmp):
app/controllers/users_controller.rb:73:in `update'
cache: [POST /users/2] invalidate, pass

My 73 line is:

if @user.update_attributes(params[:user])

Tryed to make this om local computer and push to heroku and failed

What else can I do?

回答1:

You can't store files on Heroku's servers, so uploading and trying to save files to the local filesystem will not work.

Instead, you should probably upload files to S3. The Heroku documentation and CarrierWave documentation both have information on configuring CarrierWave to upload files to S3 via fog. Check out the documentation, get an S3 account, and upload your files there.



回答2:

When you push to Heroku your app is compiled into a slug that runs on a read-only filesystem - so you cannot write to it whatsoever (i.e. you cannot even write to your own app's public directory). To make Carrierwave work on Heroku, you must set the cache_dir in your Uploader class. Have a look a this answer, and particularly the comment that says "These two lines fixed it":

config.root = Rails.root.join('tmp')
config.cache_dir = 'carrierwave'