Project

asset_oss

0.01
No commit activity in last 3 years
No release in over 3 years
asset_oss is a library for uploading static assets to Aliyun OSS.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

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