Giter Club home page Giter Club logo

paperclip-dropbox's Introduction

This gem is not maintained anymore and became obsolete. Over time Dropbox made some significant changes to its API, which breaks this gem's core functionality. You shouldn't be using it anymore.

While we're here, you also shouldn't be using Paperclip anymore, you should use Shrine instead.


Paperclip Dropbox

This gem extends Paperclip with Dropbox storage.

Setup

gem "paperclip-dropbox", ">= 1.1.7"

Example:

class User < ActiveRecord::Base
  has_attached_file :avatar,
    :storage => :dropbox,
    :dropbox_credentials => Rails.root.join("config/dropbox.yml"),
    :dropbox_options => {...}
end

Your config/dropbox.yml:

app_key: "..."
app_secret: "..."
access_token: "..."
access_token_secret: "..."
user_id: "..."
access_type: "dropbox|app_folder"

You can also pass a Proc to :dropbox_credentials, if you want the credentials to be dynamically evaluated.

In order to fill these in, you must create a Dropbox app and authorize it. There are two types of Dropbox apps: App folder or Full Dropbox. You can read about the differences and gotchas in this wiki. When you decide, don't forget to put "dropbox" or "app_folder" as the :access_type in your credentials.

After you have created an app, you will be given the "App key" and "App secret". Provide these and the access type to the authorization Rake task:

$ rake dropbox:authorize APP_KEY=your_app_key APP_SECRET=your_app_secret ACCESS_TYPE=dropbox|app_folder

For non-Rails projects, you must require this task in your Rakefile:

# Rakefile
load "paperclip/dropbox/tasks.rake"

Follow the instructions, and it will authorize the Dropbox app and output the rest of the credentials. Then you can fill in the rest of config/dropbox.yml.

And that's it. Everything should work now :)

The :dropbox_credentials option

:dropbox_credentials => Rails.root.join("config/dropbox.yml")
# or
:dropbox_credentials => {app_key: "foo", app_secret: "bar", ...}

For the list of required credentials, take a look at the config/dropbox.yml above.

The YAML file supports ERB:

app_key: <%= ENV["DROPBOX_APP_KEY"] %>

And it supports environment nesting (just like database.yml):

development:
  app_key: "..."
  ...
production:
  app_key: "..."
  ...

The :dropbox_options option

This is a hash containing any of the following options:

  • :environment – String, the environment name to use for selecting namespaced credentials in a non-Rails app

For example:

class User < ActiveRecord::Base
  has_attached_file :avatar,
    :storage => :dropbox,
    :dropbox_credentials => Rails.root.join("config/dropbox.yml"),
    :dropbox_options => {environment: ENV["RACK_ENV"]}
end

In Rails you don't need to specify it.

The :dropbox_visibility option

This is a string "public" (default) or "private".

  • "public" - Files will be placed in your "Public" directory in dropbox and will the public urls will be used to access the files (not http request required to get a url for the file)
  • "private" - Files can be placed in any dropbox directory (set your :path attachment option) and private, expiring urls (4 hours) will be generated each time you access this file. Private can only be used with the 'dropbox' access type.
class User < ActiveRecord::Base
  has_attached_file :avatar,
    :storage => :dropbox,
    :dropbox_credentials => Rails.root.join("config/dropbox.yml"),
    :dropbox_visibility => 'public'
end

The :path option

To change the path of the file, use Paperclip's :path option:

:path => ":style/:id_:filename"  # Defaults to ":filename"

In "Full Dropbox" mode with "public" visibility it will automatically be searched in the Public folder, so there is not need to specify it.

URL options

If you want to force the browser to always download the file, you can use the :download option.

user.avatar.url(:download => true)

Check if the file exists

It may happen that a file on Dropbox gets deleted remotely. To check this in your application, you can use the #exists? method:

user.avatar.exists?
# user.avatar.exists?(style)

License

MIT License

paperclip-dropbox's People

Contributors

cesarfigueroa avatar digitalcora avatar dilshod avatar dougbradbury avatar dukz avatar janko avatar jdtanacredi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

paperclip-dropbox's Issues

403 on Rake task

Just adding this to a Rails 3.2.13 app. I created the Dropbox app just for this use but when I run the rake task I get an error:

Error getting request token. Is your app key and secret correctly set? Server returned 403: Forbidden.

Screen Shot 2013-04-24 at 7 38 19 AM

As the screencap shows, I have set to app_folder.

Check if URL is valid

If I change the file name on dropbox (outside of the gem), then try to display the URL link with something like

<% if direct_purchase.receipt_file_size != nil %>
        <td><%= link_to direct_purchase.purchase_date, direct_purchase.receipt.url %></td>
    <% else %>
        <td><%= direct_purchase.purchase_date %></td>
    <% end %>

I get a DropboxError saying the path is not found.

Is there a way to check if the path is valid?

UrlGenerator#user_id throws an error when :dropbox_credentials is set via yaml file

I just installed this gem and followed the readme me to configure paperclip for dropbox. I used a yaml file to set my credentials.

I was able to upload to dropbox just fine, but when I tried to display my image with .url, I got the following exception:

undefined method `[]' for #Pathname:0x007fce810b02a0

After reconfirming that I had set everything up correctly, I traced the code and discovered that error was occurring in UrlGenerator#user_id.

def user_id
    @attachment_options[:dropbox_credentials][:user_id]
end

For some reason @attachment_options[:dropbox_credentials] is not a hash, but a Pathname. Since it's a Pathname [:user_id] causes an exception. If i change :dropbox_credentials to a hash in my model, @attachment_options[:dropbox_credentials] is a hash and everything works as expected.

My system configuration is:

ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin14.0]
Rails 4.1.1
paperclip (4.2.1)
paperclip-dropbox (1.3.0)

Two images with the same name in the same model collide

So, I have a model which has two icons:

class Category < ActiveRecord::Base
  has_many :events

  has_attached_file :black_icon, styles: { small: '30x30' },
    storage: :dropbox,
    dropbox_credentials: Rails.root.join('config/dropbox.yml')

  has_attached_file :white_icon, styles: { small: '30x30' },
    storage: :dropbox,
    dropbox_credentials: Rails.root.join('config/dropbox.yml')
end

If I use ActiveAdmin to upload two files named computing.png, both files do show up in my Dropbox folder (along with their :small variations). However, on trying to display the images, both are the same, either both black or both white.

Sorry for the lack of specificity, I'm just getting started with Rails. However, this was not an issue when not using paperclip-dropbox.

Not able to access the image from dropbox

I have integrated paperclip-dropbox in my application and follwed all steps as described. Its working fine if I am storing an image. The image is properly being saved in my dropbox account. But when i try to access the image using the url generated by paperclip, the image is not found.

Even if i try the url in a seperate tab, it says:

Error (404)
We can't find the page you're looking for. Check out our Help Center and forums for help, or head back to home.

Does anyone have any idea, how to access the image from dropbox using this paperclip-dropbox gem or i am missing something.

How can I download a file that I uploaded with paperclip-dropbox

Hello,

I am having a difficult time figuring out how to download a file via the browser after it has been uploaded using paperclip-dropbox. My original plan was to download the file using httparty then use send_file to present the file. This has not been working for me. Even if it has, because my app is hosted on herokuapps.com I doubt that I would be able to use this same tactic.

Is there a particular way that I need to go about doing this?

Compatibility with paperclip 4.1

Hi Janko,

Thank you for creating this excellent gem! I'm a Rails instructor for BaseRails (www.baserails.com) and for the past couple months, I've been teaching my students to use your gem for image hosting due to its ease of use over other alternatives.

A few days ago, one of my students notified me about the recent update to the paperclip gem (http://www.theregister.co.uk/2014/02/09/content_type_spoofing_bug_in_ror_paperclip/). I've been telling them to hold off on upgrading to paperclip 4 because paperclip-dropbox still relies on paperclip 3. Are you planning to update your gem to the latest version of paperclip? Please let me know - thanks!

Best,
Alex

dropbox_credentials and proc

Is it possible to do something like this:

dropbox_credentials: Proc.new do |a|
    {
        app_key: "xxxxxxxxxxxxxxx", 
        app_secret: "xxxxxxxxxxxxxxx", 
        user_id: "xxxxxxxx",
        access_type: "app_folder",
        access_token: a.instance.user.token, 
        access_token_secret: a.instance.user.secret
    }
end

What I am trying to do is get the user's token and secret that belongs to this model (asset). Something kind of similar but for S3: http://rubydoc.info/gems/paperclip/Paperclip/Storage/S3.

Any help will be much appreciated, thanks!

Deleting avatar on dropbox?

When i delete instance of model in my application by using destroy method - image - in dropbox still remain. Should it be deleted or not?

paperclip-dropbox evaluating nil.[] error

Just trying out paperclip-dropbox but without much success. Here what I have done.

In my Gemfile:

gem 'paperclip'
gem "paperclip-dropbox"

Created an App on dropbox and followed these instructions: https://github.com/janko-m/paperclip-dropbox

In my dropbox.yml

development:
  app_key: APP_KEY
  app_secret: APP_SECRET
  access_token: ACCESS_TOKEN
  access_token_secret: ACCESS_TOKEN_SECRET
  user_id: USER_ID

production:
  app_key: APP_KEY
  app_secret: APP_SECRET
  access_token: ACCESS_TOKEN
  access_token_secret: ACCESS_TOKEN_SECRET
  user_id: USER_ID

In my User model:

has_attached_file :avatar, 
  :styles => {
    thumb: '100x100>',
    square: '200x200#',
    medium: '300x300>' }

In my view:

<%= image_tag @user_profile.avatar.url(:square), :size => '100x100' %>

Error message:

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]  
Pointing at my image_tag line of code.

Note that paperclip worked real well using the local filesystem.

Any ideas?

Can't load image from dropbox

Hi

I have a problem with load file (in this case is image) from dropbox. I want to create a user that have an avatar like a demo in here, with a little modification. I tried to upload an image and the image is uploaded successfully in dropbox, and my table (in this case users table) was updated, but it can't be loaded. I have seen this issue, but it didn't work. Here is my code:

Gemfile

# another gem
gem 'paperclip-dropbox', '>= 1.1.17'

AccountController.rb

class AccountController < ApplicationController

  def show
    @user = User.find(params[:id])
  end

  def edit_account
    @user = User.find(current_user.id)
  end

  def update_account
    @user = User.find(current_user.id)
    if @user.update(account_params)
      redirect_to(profile_path(@user.id))
    else
      render 'edit_account'
    end
  end

  private
    def account_params
      params.require(:user).permit(:username, :email, :first_name, :last_name, :birth_date, :gender, :avatar)
    end
end

user.rb

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable, :registerable
  devise :database_authenticatable,
         :recoverable, :rememberable, :trackable, :validatable

  ROLES = %w[admin user banned]
  GENDERS = %w[male female]

  validates :username, presence: true, length: { in: 4..20 },
    :uniqueness => {
      :case_sensitive => false
    },
    format: { with: /_*[A-Za-z0-9]+\w*/, message: 'only allows word character'}

  has_attached_file :avatar,
    :storage => :dropbox,
    :styles => { :medium => "300x300>", :thumb => "100x100>" },
    :dropbox_credentials => Rails.root.join("config/dropbox.yml"),
    :dropbox_visibility => 'public',
    :dropbox_options => { }

  validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/

  def age
    now = Time.now.utc.to_date
    return now.year - birth_date.year - (birth_date.to_date.change(:year => now.year) > now ? 1 : 0)
  end

  def has_role?(role)
    return self.role == role.to_s
  end
end

edit_account.html.erb

<%= form_for @user, :url => edit_account_path(@user), :html => { :multipart => true } do |f| %>
  <div class="row">
    <div class="small-3 columns">
      <%= f.label(:avatar, :class => 'right inline required') %>
    </div>
    <div class="small-9 columns">
      <%= f.file_field :avatar %>
    </div>
  </div>
  <div class="row">
    <div class="large-offset-3 large-9 columns">
      <%= f.submit 'Save changes', :class => 'button' %>
    </div>
  </div>
<% end %>

show.html.erb

<%= image_tag @user.avatar.url %>

routes.rb

Rails.application.routes.draw do
  device_for :users
  resources :users
  get 'welcome/index'

  # I separate it from Devise's and UsersController's routes
  # Account settings
  get 'profile/:id', to: 'account#show', as: 'profile'
  get 'settings/account', to: 'account#edit_account', as: 'edit_account'
  patch 'settings/account', to: 'account#update_account'
  put 'settings/account', to: 'account#update_account'

  root 'welcome#index'
end

my migration file with .rb extension

class AddAvatarToUsers < ActiveRecord::Migration
  def self.up
    add_attachment :users, :avatar
  end

  def self.down
    remove_attachment :users, :avatar
  end
end

it created 4 new columns: avatar_file_name, avatar_content_type, avatar_file_size, and avatar_updated_at

and dropbox.yml

app_key: "q45pb9tzxxxxxxx"
app_secret: "gbt9nw02xxxxxxx"
access_token: "qd7csbjebxxxxxxx"
access_token_secret: "pni29r74xxxxxxx"
user_id: "293122165"
access_type: "dropbox"

First, I try to upload an image (it use edit_account.html.erb). After upload the image, open route /profile/:id, that render show.html.erb, the tag <%= image_tag @user.avatar.url %> give me a result <img alt="2426742 41674 108550" src="https://dl.dropboxusercontent.com/u/293122165/2426742-41674-108550.jpg" />. I try to go to that link with my browser, it says "Not Found The resource could not be found." What's wrong with my code? Or, my dropbox app is the problem? I don't know how to create dropbox app because I didn't found any tutorial how to create it.... So, I try to create Dropbox app with some guessing:

  1. Go to this link
  2. Click Dropbox API app
  3. It asks What type of data does your app need to store on Dropbox? so I choose Files and datastores
  4. It asks Can your app be limited to its own folder? so I choose No My app needs access to files already on Dropbox.
  5. What type of files does your app need access to? and then I choose All file types My app needs access to a user's full Dropbox. Only supported via the Core API.
  6. And it asks Provide an app name, and you're on your way. and I typed my app name there.

The result is my dropbox app settings:
Status: Development
Development users: Only you
Permission type: Full Dropbox
App key: q45pb9tzxxxxxxx
App secret: gbt9nw02xxxxxxx
OAuth2: Redirect URIs <-- I leave it blank because I don't understand what is it used for.
Allow implicit grant: Allow
Drop-ins domains: <-- I leave it blank because I don't understand what is it used for.
Webhooks: Webhook URIs <-- I leave it blank because I don't understand what is it used for.

Did I miss something? Or, did I happen something wrong? I try this in development mode.

Thanks

Getting 'DropboxError (Forbidden)' on file upload

I just switched from the app folder option to the public directory because of the latency from dropbox.

The only thing is that now file uploads don't work anymore, i get a 'DropboxError (Forbiden)'. I triple checked my newly generated credentials in my credentials file and setted access_type to dropbox.

Here is what i did :
rake dropbox:authorize APP_KEY= APP_SECRET= ACCESS_TYPE=dropbox
Then authorized and successfuly got my credentials
Added everything to a config/dropbox.yml following the structure in the example but without the environnement variables.
Then left everything else the same way

I made a custom path for my images. Can it be the source of the problem maybe ?

If it can help i'm using the latest commited version from your repo (because i need default url interpolation).

Thank you for your help

model_obj.attachment_name.exists? raises TypeError

Hi,

I noticed that calling model_obj.attachment_name.exists? when the model does not have an attachment (in my application it is optional) raises a TypeError:

[1] pry(main)> e = Entry.find_by_title "foobar"
[2] pry(main)> e.photo.exists?
TypeError: no implicit conversion of nil into String
from /Users/Tom/.rvm/gems/ruby-2.0.0-p195/gems/paperclip-dropbox-1.1.5/lib/paperclip/storage/dropbox/path_generator.rb:37:in `extname'

I could fix this by implementing a custom query method:

  def photo_exists?
    return self.photo.exists?
  rescue TypeError => er
    return false
  end

so that:

[5] pry(main)> e.photo_exists?
=> false

rake dropbox:authorize returns 401

Credentials are ok, because if I visit the URL in my browser I can authorize my app but from the command line I get a 401.

DropboxAuthError: Couldn't get access token.  Server returned 401: Unauthorized.

dropbox:authorize rake task always runs twice

When doing the rake dropbox:authorize APP_KEY=your_app_key APP_SECRET=your_app_secret rake task, it provides an authorization URL and then gives the access token/secret with user id. But then it does that all again for some reason.

expiration date for a shared link

When i upload file(pdf) via my app, I see that the default expiration date for all files is 0 day,
is there any way to upload file without existing of expiration date ? thanks

Shouldn't User Id be optional for Folder Apps?

I'm looking through the source code and it appears that the user_id is only needed for app folder, so should this be optional? Also I have no idea where to get my user_id dropbox from, some instructions would help.

:default_url paperclip is not working

Hello, i have used the :default_url option in my user model and created the correct files in my asset pipeline. the user model looks like this:
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>", :small=>"80x80>" }, :default_url => ActionController::Base.helpers.asset_path("Bob_:style.jpg")

and i have a imges/Bob_small.jpg etc..

can someone tell me please why is this not working?

Forbidden error when uploading

I am using gem "figaro" to host my variables and the form is a a nesteed form using the gem "nested_form". I was also able to get the user information information without a problem previously.

class LineImage < ActiveRecord::Base
  belongs_to :line_item
  attr_accessible :image, :location
  has_attached_file :image,
    storage: :dropbox,
    dropbox_credentials: {
        app_key: ENV['DROPBOX_APP_KEY'], 
        app_secret: ENV['DROPBOX_APP_SECRET'], 
        access_token: ENV['DROPBOX_ACCESS_TOKEN'],
        access_token_secret: ENV['DROPBOX_ACCESS_TOKEN_SECRET'],
        user_id: ENV['DROPBOX_USER_ID']
    }
  validates_presence_of :location
end

And my full-trace from the error:
https://gist.github.com/blklane/7753096

NoMethodError (undefined method `gsub' for nil:NilClass)

Hi.. I know this it a old issue (issues number 13). I'm using this gem with active-admin gem.

this is the model

class Category < ActiveRecord::Base
  has_many :photo
  validates_presence_of :name
  attr_accessible :name, :desc

  attr_accessible :image

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

  validates :name, :uniqueness => true
  validates_attachment_presence :image
  validates_attachment_size :image, :less_than => 1.megabytes
  validates_attachment_content_type :image, :content_type => ['image/jpeg', 'image/png']

end

active_admin DSL file

ActiveAdmin.register Category do

  index do
    selectable_column
    column :name
    column :image_file_name do |photo|
      image_tag photo.image.url(:thumb)
    end
    default_actions
  end

  form do |f|
    f.inputs "Category Details" do
      f.input :name
      f.input :desc, :lable => "Description", :input_html => { :class => "tinymce" }
      f.input :image, :as => :file
    end
    f.buttons
  end

end

config/dropbox.yml

app_key: <%= ENV["n3agsxxxxxxx"] %>
app_secret: <%= ENV["3xi0xxxxx"] %>
access_token: <%= ENV["7uxxxxxxx"] %>
access_token_secret: <%= ENV["28xxxxxx"] %>
user_id: <%= ENV["11xxxxxxx"] %>
access_type: <%= ENV["app_folder"] %>
Category.new.image.send(:dropbox_client).instance_variable_get("@session").instance_variable_get("@consumer_key")
=> nil

SSL error connecting to Dropbox

I was attempting to install your gem and ran into an issue. I wasn't sure if I should put this issue on github or if it was just something I am not doing correctly.

Here is what I did step by step, maybe you can see where I am doing something wrong.

  • Installed paperclip
  • Installed paperclip-dropbox
  • generated paperclip fields for db
  • rails g paperclip blog document
  • added the following:
has_attached_file :document,
  storage: :dropbox,
  dropbox_credentials: {
    app_key: List.where(name: 'blog_dropbox_key').first.list,
    app_secret: List.where(name: 'blog_dropbox_secret').first.list,
    access_token: "..."
    access_token_secret: "..."
    user_id: "[email protected]"
    access_type: "dropbox"},
  dropbox_options: {environment: Rails.env}
  • Tried to authorize my application for use with dropbox:
rake dropbox:authorize [email protected] APP_SECRET=mypassword ACCESS_TYPE=dropbox

I get the following error when I run that last comment:

rake aborted!
SSL error connecting to Dropbox.  There may be a problem with the set of certificates in "/Users/vmcilwain/.rvm/gems/ruby-2.0.0-p247/gems/dropbox-sdk-1.6.3/lib/trusted-certs.crt".  SSL_connect returned=1 errno=0 state=SSLv3 read server key exchange B: bad ecpoint
/Users/vmcilwain/.rvm/gems/ruby-2.0.0-p247/gems/dropbox-sdk-1.6.3/lib/dropbox_sdk.rb:90:in `rescue in do_http'
/Users/vmcilwain/.rvm/gems/ruby-2.0.0-p247/gems/dropbox-sdk-1.6.3/lib/dropbox_sdk.rb:87:in `do_http'
/Users/vmcilwain/.rvm/gems/ruby-2.0.0-p247/gems/dropbox-sdk-1.6.3/lib/dropbox_sdk.rb:250:in `do_get_with_token'
/Users/vmcilwain/.rvm/gems/ruby-2.0.0-p247/gems/dropbox-sdk-1.6.3/lib/dropbox_sdk.rb:262:in `get_token'
/Users/vmcilwain/.rvm/gems/ruby-2.0.0-p247/gems/dropbox-sdk-1.6.3/lib/dropbox_sdk.rb:280:in `get_request_token'
/Users/vmcilwain/.rvm/gems/ruby-2.0.0-p247/gems/dropbox-sdk-1.6.3/lib/dropbox_sdk.rb:286:in `get_authorize_url'
/Users/vmcilwain/.rvm/gems/ruby-2.0.0-p247/gems/paperclip-dropbox-1.2.1/lib/paperclip/dropbox/rake.rb:11:in `authorize'
/Users/vmcilwain/.rvm/gems/ruby-2.0.0-p247/gems/paperclip-dropbox-1.2.1/lib/paperclip/dropbox/tasks.rake:11:in `block (2 levels) in <top (required)>'
/Users/vmcilwain/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval'
/Users/vmcilwain/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => dropbox:authorize
(See full trace by running task with --trace)

Got any ideas?

Thanks,

Not working in Heroku

Everything works perfect locally. However, when I push everything to Heroku, my uploads using paperclip-dropbox fail:

Completed 500 Internal Server Error in 2ms
2012-11-07T23:39:59+00:00 app[web.1]: 
2012-11-07T23:39:59+00:00 app[web.1]: Paperclip::Error (Post model missing required attr_accessor for 'photo_file_name'):
2012-11-07T23:39:59+00:00 app[web.1]:   app/controllers/posts_controller.rb:43:in `new'
2012-11-07T23:39:59+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"+IqmFBMuAXmI5LTnMsTfQA5CFwfLi2uh0tZ1gqf0pcQ=", "post"=>{"content"=>"This is the greatest explanation of cell division EVER!", "image"=>"", "title"=>"Cell Division", "icon"=>"", "photo"=>#<ActionDispatch::Http::UploadedFile:0x0000000368b160 @original_filename="celldivision.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"post[photo]\"; filename=\"celldivision.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/tmp/RackMultipart20121107-2-5t19gm>>}, "commit"=>"Create Post"}
2012-11-07T23:39:59+00:00 app[web.1]:   app/controllers/posts_controller.rb:43:in `create'

Support

Hi,

I've noticed that it takes a couple of seconds for the Dropbox API to generate a URL.
Would it be safe to cache them in a DB column? I can't find any information on Dropbox URL expiration (for applications).

Thanks!

Not working in Nested Form

I keep getting:

undefined method `image' for #<LineImage:0x007fef5daa2220>

I had the original paperclip gem when I created the model/attribute then then changed it out for this gem and it no longer works, any Ideas? I am using the LineImage in a nested_form thanks to the gem "nested_form"

class LineImage < ActiveRecord::Base
  belongs_to :line_item
  attr_accessible :image, :location
  has_attached_file :image,
    storage: :dropbox,
    dropbox_credentials: {
        app_key: ENV['DROPBOX_APP_KEY'], 
        app_secret: ENV['DROPBOX_APP_SECRET'], 
        access_token: ENV['DROPBOX_ACCESS_TOKEN'],
        access_token_secret: ENV['DROPBOX_ACCESS_TOKEN_SECRET'],
        user_id: ENV['DROPBOX_USER_ID'],
        access_type: dropbox
    },
    dropbox_options: {path: proc { "#{id}_#{image.original_filename}"}},
    unique_filename: true
  # validate :validates_presence_of_image
  validates_presence_of :location, :image

  # def validates_presence_of_image
  #     return (image.exists? ? true : false)
  # end
end

Private/Public visibility and file path

Hi Janko,

First off, thanks for a great gem! I wanted to see when pull request #31 will be incorporated to the gem (or if it already is I could be doing something wrong). I'm trying to save a file a specific folder w/in dropbox and after looking at the updated source code I thought it should work by setting the :dropbox_visibility => 'private' and also by specifying the desired path. After a few tries I notice the code dropbox.rb code in my app didn't match what I was seeing on github, Screenshot http://d.pr/i/gatW.

Please let me know if this makes sense...or if I'm totally off...and thanks again for your help!

Quin

Very slow url loading

_image.html.slim

= image_tag image.data.url(:medium)

images.rb

has_attached_file :data, styles: { small: '100x100#', medium: '200x200#' }, storage: :dropbox, dropbox_credentials: Rails.root.join("config/dropbox.yml"), path: ":style/:id_:filename"

Rendered images/_image.html.slim (1267.1ms)

This is only one image. WTF ?
How this fix ?

NoMethodError in Members#home

good-evening

I have created a small application, using device,paperclip

when i am put this "<%= image_tag @user.pic.url %>" code in index.html.erb
then i am face this error "undefined method `pic' for nil:NilClass"

os Windows 8
ruby 1.9.2
rails 3.2.1

i am following these steps

$ rails g scaffold user name:string email:string
gem 'paperclip', '3.0.4'
$ rails g migration add_pic_paperclip

class AddPicPaperclip < ActiveRecord::Migration
2 def self.up
3 add_column :users, :pic_file_name, :string
4 add_column :users, :pic_content_type, :string
5 add_column :users, :pic_file_size, :integer
6 add_column :users, :pic_updated_at, :datetime
7 end
8
9 def self.down
10 remove_column :users, :pic_file_name
11 remove_column :users, :pic_content_type
12 remove_column :users, :pic_file_size
13 remove_column :users, :pic_updated_at
14 end
15 end

$ rake db:migrate

1 class User < ActiveRecord::Base
2 validates :name, :presence => true
3 validates :email, :presence => true
4 has_attached_file :pic, :styles =>
5 { :medium => "300x300>", :thumb => "100x100>" }
6 has_attached_file :attach
7 end

<% form_for @user, :html => { :multipart => true } do |f| %>
<%= f.file_field :pic %>

<%= image_tag @user.pic.url %>

Please help me to resolve this problem

image url not working

when I get the image url through User.first.avatar.url, It generate the url but when I try the url in browser or html, its not showing the image. My model code

has_attached_file :avatar,
    :storage => :dropbox,
    :dropbox_credentials => {app_key: "123445", app_secret: "1234456", access_token: "123456", access_token_secret: "123456", user_id: "191409863"}

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

It is uploading the file to my dropbox successfully. So when I try User.first.avatar.url, its generates url like this https://dl.dropboxusercontent.com/u/191409863/mclarenp1_QY5vmfTw.jpg when I access this, the page shows dropbox error page instead on image.

Renaming dropbox url's

It's very difficult at the moment to change the Model.attachment.url's(dropbox url's).

Example:

class Item < ActiveRecord::Base
    has_attached_file :picture_1, { dropbox_options: { path: proc { "#{self.id}_1" }  }, default_url: "default.png" }
    has_attached_file :picture_2, { dropbox_options: { path: proc { "#{self.id}_2" }  }}
    has_attached_file :picture_3, { dropbox_options: { path: proc { "#{self.id}_3" }  }}

    validates_attachment_content_type :picture_1, content_type: /\Aimage\/.*\Z/
    validates_attachment_content_type :picture_2, content_type: /\Aimage\/.*\Z/
    validates_attachment_content_type :picture_3, content_type: /\Aimage\/.*\Z/

end

Also I have to manually add a callback when the models referred to self.id changes.(eg. if we change the id of an item that has an attachment, dropbox url wont change automatically so samemodel.picture_1.url would cause an error).

I think we need a better API + handling for dropbox uploads.

:class parameter in path doesn't work as expected

The readme says that the :path parameter works similar to paperclip's path parameter. However, when I tried to utilize the a path schema like paperclip's default which places it in a folder by class using ":class", I found it was simply stored under a folder called ":class" instead of the class name.

I looked through all the documentation I could find in both your gem and paperclip's as well as google for a few days now, but could not find a way to get the class name inside of the dropbox path.

class ClassSession < ActiveRecord::Base
  attr_accesible :icon
  has_attached_file :icon,
    styles: { icon: "65x65^"},
    :storage => :dropbox,
    :dropbox_credentials => "#{Rails.root}/config/dropbox.yml",
    :dropbox_options {
      path: proc { |style| "MyApp/:class/#{style}/#{id}" },
    }
end

Expected result: file saved at Public/MyApp/ClassSession/icon/1_icon.png
Actual result: file saved at Public/MyApp/:class/icon/1_icon.png

How would I be able to achieve this?

And as a side question, why doesn't the gem use paperclip's path parameter instead of its own?

Can we save the dropbox image_url to a table's attribute?

I have users table and I call the user's image_url on a view like this:

current_user.image.url

but sometimes it very slow because It's requesting the url from Dropbox every time you load the view.

I'm thinking of a callback and add the dropbox url to an attribute:
I have avatar_url on users table.

I tried to use

before_save :set_avatar_url

private

def set_avatar_url
   self.avatar_url = logo.url
end

but I'm getting

Path '/14556_937298776286928_704613103_n.png' not found

Image Tag URL Is Not Working

Seems like I'm able to upload an image to dropbox, it appears in my Public folder as:
tumblr_mbc58jDnZz1rshp39o5_250.png (there are 2 more files with thumb and medium appended)
Should they be in directories within the Public directory?

When I want to display an image:
<%= image_tag @post.photo.url(:medium) %>
The image is broken, the URL which is output in HTML is:
http://dl.dropbox.com/u/112885775/tumblr_mbc58jDnZz1rshp39o5_250_medium.png

If I go to that image, I get a 404 error.

What do I do?

error when uploading files

I followed all the instructions, having previously successfully implemented paperclip-dropbox. But I'm getting this error whenever I upload a file:

Image /var/folders/7x/y47hx14s11vf895wwgk9rkqw0000gn/T/Henry 00420121019-852-12mfi2c.jpg is not recognized by the 'identify' command.

I have an older dropbox account with an existing Public folder, but I enabled it anyway.

NoMethodError (undefined method `gsub' for nil:NilClass)

Hello!

I have created a small application, using the instructions from the readme file.

Here is the model code:

class User < ActiveRecord::Base
  attr_accessible :avatar
  has_attached_file :avatar, 
    :styles => { :medium => "300x300>", :thumb => "100x100>" },
    :storage => :dropbox,
    :dropbox_credentials => "#{Rails.root}/config/dropbox.yml",
    :dropbox_options => {
      :path => proc { |style| "#{style}/#{id}_#{avatar.original_filename}" }
    }
end

Here is the controller code:

class UsersController < ApplicationController

  def new
    @user = User.new
  end

  def create
    @user = User.new( params[:user] )
    if @user.save
      redirect_to @user
    else
      render :action => "new"
    end
  end

  def show
    @user = User.find(params[:id])
  end

end

So when I try to create a new user, server throws an error:

[paperclip] Saving attachments.
   (0.8ms)  rollback transaction
Completed 500 Internal Server Error in 2072ms

NoMethodError (undefined method `gsub' for nil:NilClass):
  app/controllers/users_controller.rb:9:in `create'

Local storage works just fine. Could you please look at this?

Upload Problem

my rails app is configured to use the app_folder access but when I try to upload a file in development, Rails throws me this error:

Host: rpc.dropbox.com:443, FE: None, X-Dropbox-RequestId: None, X-Dropbox-App-Error: None, Full Dropbox access attempt failed because this app is not configured to have full Dropbox access.  Should your access type be app folder ('sandbox') instead?

At first I thought maybe I entered the value wrong. My variable looks like this:

DROPBOX_ACCESS_TYPE: app_folder

Any ideas?

Getting progress on upload.

This isn't really and issue, but It obviously takes a little while for a picture to be uploaded to dropbox.
For user experience's sake I would like to display an progress bar. Is it possible to do so?

Obsolete

This gem core purpose renders obsolete as there's no posibility for a normal account to have a public folder. All links created by model.url get a 403 reposnse.

This gem was awsome but please update its readme so no more people lose their time as I did.

Thank you.

:app_key credential is nil

Hello. I followed the post of you and took a searched on google and found nothing relating to this error. will be someone who could help me? thank you

  • the error:
:app_key credential is nil
  • the model:
has_attached_file :image,
    :storage => :dropbox,
    :dropbox_credentials => "#{Rails.root}/config/dropbox.yml",
    :styles => { :original => '670x365#',:big => "550x550#",:medium => "400x400#",:small => "50x50#"},
    :dropbox_options => {:path => proc { |style| "#{style}/#{id}_#{image.original_filename}" }}
  • the config/dropbox.yml
development:
    app_key:                <%= ENV["5lhbi547cja849d"] %>
    app_secret:             <%= ENV["khzu0wikjxgo7se"] %>
    access_token:           <%= ENV["kw91h3cxpadr8tt"] %>
    access_token_secret:    <%= ENV["acb2v71pbp5b3b1"] %>
    user_id:                <%= ENV["153413001"] %>
    access_type:            <%= ENV["dropbox"] %>

Doesnt storage in dropbox

Hi,

I have following the setup installation of the paperclip-dropbox for rails.

I have this in my listing.rb file

class Listing < ActiveRecord::Base
has_attached_file :image, :styles => { :medium => "200x>", :thumb => "100x100>" }, :default_url => "default.jpg"
validates_attachment_content_type :image, :content_type => %w(image/jpeg image/jpg image/png), 
        :storage => :dropbox,
    :dropbox_credentials => Rails.root.join("config/dropbox.yml"),
    :path => ":style/:id_:filename"
end

When i upload an image, it storages in my localhost folder and not in the dropbox.

Renaming Files after Upload

I'm naming my files based on some record entries (date for example). If one of these data fields is changed by the user, I would like to rename the file to match. Is it possible to do this?

Able to upload an image to Dropbox but cannot get and store the image url on Database

Hi @janko-m I'm using paperclip-dropbox >= 1.1.7
then here are my attributes:

  • avatar
  • avatar_file_name
  • avatar_content_type
  • avatar_file_size:
  • avatar_updated_at:

and in my form:

= f.file_field :avatar

and in my model

  has_attached_file :avatar,
        :storage => :dropbox,
        :dropbox_credentials => Rails.root.join("config/dropbox.yml"),
        :dropbox_visibility => 'public'

then when I add an image I can upload the image to dropbox and
these attributes has a values avatar_content_type, avatar_file_size, avatar_updated_at
but it cannot store the uploaded image url. Please help thanks!

PS. I'm using a non-premium dropbox account and the images we're uploaded in Apps/my_images folder in Dropbox.

Cannot load storage module 'Dropbox'

Hello !

I have a problem when I try to show a picture.

I follow the readme and I have no problem to upload. But, when I try to show I picture, I have this error :

Cannot load storage module 'Dropbox'

Any ideas ?

Thanks !

DropboxError: Forbidden when attempting to upload file

I have been attempting to upload a file via the rails console and have not had any luck. Unfortunately the only error I get is DropboxError: Forbidden. The log file doesn't show any additional errors so I'm at a loss on how to debug this. What I have in my model is:

has_attached_file :document,
                     storage: :dropbox,
                     dropbox_credentials: {
                       app_key: "...",
                       app_secret: "...",
                       access_token: "...",
                       access_token_secret: "...",
                       user_id: "123456789"
                     },
                     dropbox_options: {environment: Rails.env},
                     access_type: 'app_folder
 validates_attachment_content_type :document, :content_type => /\Aimage\/.*\Z/

I am looking for any ideas on how I can figure out is not right and how I can fix it so I can upload a file to my dropbox account. Any help is appreciated.

Error running RAKE

After I run the rake task, I get this:

And after you approved the authorization confirm it here (y/n): y
rake aborted!
ArgumentError: root must be :dropbox, :app_folder, or :auto
/home/vagrant/.rvm/gems/ruby-2.1.2@vaipradisney/gems/dropbox-sdk-1.6.4/lib/dropbox_sdk.rb:738:in `initialize'

Image_tag no longer working

I've had this gem running for over a year with no issues. Suddenly after my last Gemfile update, I am getting this error for every view reference to an uploaded file:

View:
<%= image_tag current_user.avatar.url(:thumb) %>

Error:
ActionView::Template::Error (no implicit conversion of Symbol into Integer):

Confirmed that current_user.avatar.url and current_user.avatar.url(:thumb) both throw this error in the console as well.

For now I changed the view to this:
<%= image_tag current_user.avatar.dropbox_client.media(current_user.avatar.path)["url"] %>

Which works, but I don't understand why the former doesn't work.

Running Railss 4.2, Paperclip 4.2, and Paperclip-Dropbox 1.2.1 ... though I tried a whole bunch of different combinations and could never resolve the error. Was unable to find a solution on StackOverflow or other forums; hoping you may have an idea. Thanks!

NoMethodError: undefined method `generate' for nil:NilClass

Hello!

I have created a small application, it works perfect locally, but when I run it in heroku it doesn't found the url and break down.
This is the code,

# app/models/image.rb
class Image < ActiveRecord::Base 
    belongs_to :store
    has_attached_file :avatar, 
        :storage =>:dropbox, 
        :dropbox_credentials => Rails.root.join("config/dropbox_config.yml"),
            :path => "app/:class/:attachment/:id/:basename.:extension"
    validates_attachment_content_type :avatar, :content_type => /^image\/(png|gif|jpeg)/
end

When I upload an image it save it correctly (the image appear in my dropbox), but it fall when i put this code to show it:
captura de pantalla 2014-06-26 a la s 17 11 27

When I run the heroku rails console "image.first.avatar.url" it tell me:
NoMethodError: undefined method `generate' for nil:NilClass

If i put "Image.first.avatar" it shows:
"=> #<Paperclip::Attachment:........."

Do you know what is wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.