samchen2009 / paperclip-storage-aliyun

Extend the Paperclip with Aliyun Storage

Home Page:https://github.com/Martin91/paperclip-storage-aliyun

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Aliyun Open Storage Service for Paperclip

This gem implement the support for Aliyun open storage service(OSS) to Paperclip.

Installation

gem install paperclip-storage-aliyun

Or, if you are using a bundler, you can append the following line into your Gemfile:

gem 'paperclip-storage-aliyun'

Configuration

In order to make all the things work, you should do some important configurations through a initializer:

If you are developing a Rails application, you can append a new initializer like:

# [rails_root]/config/initializers/paperclip-aliyun-configuration.rb
Paperclip::Attachment.default_options[:aliyun] = {
  access_id: '3VL9XMho8iCushj8',
  access_key: 'VAUI2q7Tc6yTh1jr3kBsEUzZ84gEa2',
  bucket: 'xx-test',
  data_centre: 'hangzhou',
  internal: false
}

Then, in the model which defines the attachment, specify your storage and other options, for example:

# [rails_root]/app/models/image.rb
include Paperclip::Storage::Aliyun

class Image < ActiveRecord::Base
  has_attached_file :attachment, {
    storage: :aliyun,
    styles: { thumbnail: "60x60#"},
    path: 'public/system/:class/:attachment/:id_partition/:style/:filename',
    url: "http://#{oss_connection.fetch_file_host}/public/system/:class/:attachment/:id_partition/:style/:filename"
  }
end

Thanks

这个gem是在参考Jason Lee先生写的gem carrierwave-aliyun的基础上写出来的,其中主要直接用了阿里云接口的代码以及对应的测试代码,在此基础上自行实现Paperclip必要的get方法以及exists?方法。在此特别感谢Jason Lee先生的开源代码。

About

Extend the Paperclip with Aliyun Storage

https://github.com/Martin91/paperclip-storage-aliyun


Languages

Language:Ruby 100.0%