Skip to content

Rails 3 library that uploads all static assets to aliyun oss with a unique id encoded into the path

License

Notifications You must be signed in to change notification settings

yiichou/asset_oss

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Asset OSS - 上传Rails项目静态文件到Aliyun OSS

关于

基于asset_id,aset_sync也许是更好的选择

一个简单的上传Rails assets目录里静态文件到Aliyun OSS工具

使用和配置

添加gem "asset_oss"到你的Gemfile

修改config/environments/production.rb文件, config.action_controller.asset_host = "http://my_live_bucket.oss.aliyuncs.com"

新建一个config/asset_oss.yml文件

production:
  host: 'oss.aliyuncs.com'
  access_key_id: 'MY_ACCESS_KEY'
  secret_access_key: 'MY_ACCESS_SECRET'
  bucket: "my_live_bucket"

创建rake任务, lib/tasks/asset_oss.rake

namespace :asset do
  namespace :oss do
    
    desc "uploads the current assets to aliyun oss with stamped ids"
    task :upload do
      AssetOSS::Asset.asset_paths += ['assets'] # Configure additional asset paths
      AssetOSS::OSS.upload
    end
    
  end
end

其它

也许可以通过修改Rails config.assets.prefix实现缓存过期,记得prefix要是assets开头,同时修改AssetOSS::Asset.asset_paths

About

Rails 3 library that uploads all static assets to aliyun oss with a unique id encoded into the path

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 99.4%
  • Other 0.6%