Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Ftp storage support for paperclip file attachment
Ruby
Branch: master
#1 Compare This branch is 1 commit ahead of DamianCaruso:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.document
.gitignore
LICENSE
README.rdoc
Rakefile
VERSION
init.rb
install.rb
paperclipftp.gemspec
uninstall.rb

README.rdoc

PaperclipFTP

Ftp storage support for paperclip file attachment plugin. Useful for CDNs with ftp access method for file uploading.

Install

gem install paperclipftp

Usage

In your model:

class User < ActiveRecord::Base
  has_attached_file :avatar,
                    :styles => { :medium => "300x300>", :thumb => "100x100>" },
                    :path => "/path-to-images/:attachment/:id/:style/:filename",
                    :url => "http://my-cdn-domain.com/:attachment/:id/:style/:filename",
                    :storage => :ftp,
                    :ftp_credentials => Rails.root.join('config', 'paperclipftp.yaml')
end

or

class User < ActiveRecord::Base
  has_attached_file :avatar,
                    :styles => { :medium => "300x300>", :thumb => "100x100>" },
                    :path => "/path-to-images/:attachment/:id/:style/:filename",
                    :url => "http://my-cdn-domain.com/:attachment/:id/:style/:filename",
                    :storage => :ftp,
                    :ftp_credentials => { :host => 'ftp.domain.com', :username => 'username', :password => 'password' },
                    :ftp_passive_mode => false,
                    :ftp_timeout => 90,
                    :ftp_verify_size_on_upload => false,
                    :ftp_debug_mode => false
end

Options storage, ftp_credentials, path and url are mandatory.

  • storage: Should be set to 'ftp' value in order to utilize paperclipftp plugin

  • ftp_credentials: Takes a path, a File, or a Hash. The path (or File) must point to a YAML file containing the host, username, and password to ftp server. You can 'environment-space' this just like you do to your database.yml file, so different environments can use different accounts:

    development:
      host: domain.com
      username: user
      password: password
    test:
      ...
    production:
      ...

    This is not required, however, and the file may simply look like this:

    host: domain.com
    username: user
    password: password

    In which case, those values will be used in all environments.

  • path: This is the templated path to the directory on the ftp server in which the file will be stored.

  • url: This is the templated url to the files as accessed from CDN.

Other options are optional.

  • ftp_passive_mode: True if ftp communication should happen in passive mode

  • ftp_timeout: Max amount of time in seconds to allocate to ftp operations of the plugin

  • ftp_debug_mode: If true, dumps copy of all ftp commands to stderr

  • ftp_verify_size_on_upload: If true, file size will be verified after each upload

Copyright

Copyright © 2010 Damian Caruso. See LICENSE for details.

Something went wrong with that request. Please try again.