Code Monkey home page Code Monkey logo

carrierwave-tfs's Introduction

CarrierWave for TFS

This gem adds support for Taobao TFS to CarrierWave

Installation

$ gem install carrierwave-tfs

Using Bundler

gem 'rtfs'
gem 'carrierwave-tfs'

Configuration

创建 config/initializes/carrierwave.rb

CarrierWave.configure do |config|
  config.storage = :tfs

  # == Begin 下面有两种配置方式,(TFS 客户端 或 WebService)
      
  # 客户端
  config.tfs_ns_addr = "127.0.0.1:27017"
  config.tfs_tool_path = "/usr/bin/tfstool"

  # WebService
  config.tfs_ns_addr = "http://127.0.0.1:3900"
  config.tfs_web_service_app_key = "Kshj*&2kj1"

  # 二级目录
  config.tfs_bucket = "tfscom"
  # TFS bin 文件地址, 默认 /home/admin/tfs/bin/tfstool
      
  # 域名
  config.tfs_cdn_domains = ["img01.tfscdn.com","img02.tfscdn.com"]
end

上面的配置返回的地址格式将会是这样: http://img01.tfscdn.com/tfscom/d5b5c2c676e59eb005436cd50eecce8dd4635066.jpg

关于 Model 里面

class AvatarUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick

  version :normal do
    process :resize_to_fill => [48, 48]
  end
  
  version :small do
    process :resize_to_fill => [16, 15]
  end
end

class User
  include Mongoid::Document
  
  # 需要单独定义几个字段用来存放文件地址,字段个数与 Uploader 的 version 对应,因为 TFS 每个文件名是不同的
  field :avatar_file_name
  field :avatar_normal_file_name
  field :avatar_small_file_name
  
  mount_uploader :avatar, AvatarUploader
end

carrierwave-tfs's People

Contributors

cyjake avatar huacnlee avatar kirk-ye avatar

Watchers

 avatar  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.