SantasHelper
SantasHelper

Reputation: 41

Rails paperclip-dropbox not uploading to Dropbox

I'm having some issues with the paperclip-dropbox gem.

I have a simple User model, with name, password, etc. and an image. I'm trying to upload that image to dropbox, but it's not working.

The file gets saved in my /system/users/images/000/000/ folder. The image_file_name, image_content_type, image_file_size and image_updated_at data is getting saved correctly in my database, along with the user's name, password, etc.

I'm using ruby 2.2.1p85 and Rails 4.2.0. I have the paperclip-dropbox gem in my Gemfile and correctly installed. I have created the app in Dropbox, but in the applications folder nothing gets uploaded.

It would seem like the paperclip-dropbox gem is not doing its job because I can put anything I want in my config/dropbox.yml (I mean, wrong app_key and/or access_token values, for example) and it doesn't throw any authentication error or anything.

Here's some code so you can see what I'm doing and maybe point out what's wrong:

The User model:

class User < ActiveRecord::Base
  has_attached_file :image
  validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"],
  :storage => :dropbox,
    :dropbox_credentials => Rails.root.join("config/dropbox.yml"),
    :dropbox_options => {:path => proc { |style| "files/#{id}/#{file.original_filename}" } }

end

Create method on Users Controller:

def create
  @user = User.new(user_params)

  respond_to do |format|
    if @user.save
      format.html { redirect_to @user, notice: 'User was successfully created.' }
      format.json { render :show, status: :created, location: @user }
    else
      format.html { render :new }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
end

I have the config/dropbox.yml all set.

Any suggestions? Thanks a lot in advance!

Upvotes: 2

Views: 565

Answers (1)

Lazarus Lazaridis
Lazarus Lazaridis

Reputation: 6029

Your dropbox options should be on the has_attached_file method:

has_attached_file :image,
    :storage => :dropbox,
    :dropbox_credentials => Rails.root.join("config/dropbox.yml"),
    :dropbox_options => {:path => proc { |style| "files/#{id}/#{file.original_filename}" } }

validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]

Upvotes: 2

Related Questions