Вопрос

Deployed rails app with Cloud 66, to digitalocean.com. Everything works fine, except some permission errors when trying to upload images.

 Errno::EACCES (Permission denied - /var/deploy/anabol/web_head/releases/20130608104347/public/uploads/tmp): 

image_uploader.rb

class ImageUploader < CarrierWave::Uploader::Base
...
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
...
end

There is a description, how to solve the problem here: https://www.cloud66.com/help/permission_denied_errors

I changed the store_dir path to:

  def store_dir
    "#{Rails.root}/tmp/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

But it didn't help. I still get this error:

 » 13:49:25.696 Errno::EACCES (Permission denied - /var/deploy/anabol/web_head/releases/20130608114659/public/uploads/tmp): 

Am I missing something?

Edit:

Upload works with this part in image_uploader.rb:

  def cache_dir
    # should return path to cache dir
    Rails.root.join 'tmp/uploads/cache'
  end

  def store_dir
    "#{Rails.root}/tmp/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

But now I get:

ActionController::RoutingError (No route matches [GET] "/var/deploy/anabol/web_head/releases/20130608164223/tmp/uploads/profile/image/3/thumb_Screenshot_from_2013-06-05_17_27_54.png"):

On the view, only the images path is displayed.

Это было полезно?

Решение

There are ways to get this working, on hosts where you can upload files. Two ways are described here, but had some errors, which are now corrected.: https://www.cloud66.com/help/permission_denied_errors

A working example for a deploy hook, using carrierwave for image-upload:

#! /bin/bash
#load environment variables
source /var/.cloud66_env
#assign desired permissions
sudo chmod 0777 -R $RAILS_STACK_PATH/public/uploads

And the best solution

(this way you will don't loose the images when redeploy): use this in your xy_uploader.rb:

  def store_dir
    "system/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

Другие советы

I checked out Cloud66:

This user (nginx) does not have elevated permissions, and does not have write access to your filesystem (except explicitly to the /tmp and the $RAILS_STACK_PATH/tmp folders)

This means you can't upload files to be used later to Cloud66 -- you'll want to configure Fog to upload to S3 (or any of fog's cloud file providers).

This is pretty standard among cloud providers. Tutorials:

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top