Giter Site home page Giter Site logo

mjason / carrierwave-qiniu Goto Github PK

View Code? Open in Web Editor NEW

This project forked from huobazi/carrierwave-qiniu

0.0 0.0 0.0 568 KB

Qiniu Storage support for CarrierWave

Home Page: http://rubygems.org/gems/carrierwave-qiniu

License: MIT License

Ruby 100.00%

carrierwave-qiniu's Introduction

Carrierwave::Qiniu

This gem adds storage support for Qiniu to Carrierwave

example: https://github.com/huobazi/carrierwave-qiniu-example

Installation

Add this line to your application's Gemfile:

gem 'carrierwave-qiniu'

And then execute:

$ bundle

Or install it yourself as:

$ gem install carrierwave-qiniu

Usage

You'll need to configure it in config/initializes/carrierwave.rb

::CarrierWave.configure do |config|
  config.storage             = :qiniu
  config.qiniu_access_key    = "your qiniu access_key"
  config.qiniu_secret_key    = 'your qiniu secret_key'
  config.qiniu_bucket        = "carrierwave-qiniu-example"
  config.qiniu_bucket_domain = "carrierwave-qiniu-example.aspxboy.com"
  config.qiniu_bucket_private= true #default is false
  config.qiniu_block_size    = 4*1024*1024
  config.qiniu_protocol      = "http"
end

For more information on qiniu, please read http://developer.qiniu.com/docs/v6/

And then in your uploader, set the storage to :qiniu:

class AvatarUploader < CarrierWave::Uploader::Base
  storage :qiniu
end

You can override configuration item in individual uploader like this:

class AvatarUploader < CarrierWave::Uploader::Base
  storage :qiniu

  self.qiniu_bucket = "avatars"
  self.qiniu_bucket_domain = "avatars.files.example.com"
  self.qiniu_protocal = 'http'
  self.qiniu_can_overwrite = true
  self.qiniu_bucket_private= true #default is false

    # See also:
    # https://github.com/qiniu/ruby-sdk/issues/48
    # http://docs.qiniu.com/api/put.html#uploadToken
    # http://docs.qiniutek.com/v3/api/io/#uploadToken-asyncOps
    def qiniu_async_ops
      commands = []
      %W(small little middle large).each do |style|
        commands << "http://#{self.qiniu_bucket_domain}/#{self.store_dir}/#{self.filename}/#{style}"
      end
      commands
    end

end

You can see a example project on: https://github.com/huobazi/carrierwave-qiniu-example or see the spec test on https://github.com/huobazi/carrierwave-qiniu/blob/master/spec/upload_spec.rb

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Contributors

See the Contributors List.

carrierwave-qiniu's People

Contributors

chaixl avatar chaomao avatar dorentus avatar gfreezy avatar huobazi avatar iamroody avatar mjason avatar tengcong avatar

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.