Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Carrierwave upload path to fit Cloud 66's config

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.

like image 545
Barna Kovacs Avatar asked Oct 16 '25 10:10

Barna Kovacs


2 Answers

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
like image 179
Barna Kovacs Avatar answered Oct 19 '25 00:10

Barna Kovacs


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:

  • http://railgaadi.wordpress.com/2012/06/03/saving-files-in-amazon-s3-using-carrierwave-and-fog-gem/
  • http://carrierwave.rubyforge.org/rdoc/classes/CarrierWave/Storage/S3.html
  • http://railscasts.com/episodes/383-uploading-to-amazon-s3?view=comments
like image 23
Jesse Wolgamott Avatar answered Oct 18 '25 23:10

Jesse Wolgamott



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!