Awesome Open Source
Awesome Open Source

ActiveStorage Aliyun Service

Wraps the Aliyun OSS as an Active Storage service, use Aliyun official Ruby SDK for upload.

Gem Version build


Add this line to your application's Gemfile:

gem "activestorage-aliyun"

And then execute:

$ bundle


NOTE! Current document work for Rails 6.1, if you are using Rails 6.0, please visit: You can also to use activestorage-aliyun 1.0.0 in Rails 6.0


  service: Aliyun
  access_key_id: "your-oss-access-key-id"
  access_key_secret: "your-oss-access-key-secret"
  bucket: "bucket-name"
  endpoint: ""
  # path prefix, default: /
  path: "my-app-files"
  # Bucket public: true/false, default: true, for generate public/private URL.
  public: true

Custom Domain

  service: Aliyun
  access_key_id: "your-oss-access-key-id"
  access_key_secret: "your-oss-access-key-secret"
  bucket: "bucket-name"
  endpoint: ""
  public: false
  # Enable cname to use custom domain
  cname: true

Use for image url

Original File URL:

<%= image_tag @photo.image.url %>

Thumb with OSS image service:

class Photo < ApplicationRecord
  def image_thumb_url(process)
    self.image.url(params: { "x-oss-process" => process })

And then:

<%= image_tag @photo.image_thumb_url("image/resize,h_100,w_100") %>

Use for file download

If you want to get original filename (Include Chinese and other UTF-8 chars), for example: 演示文件, you need present disposition: :attachment option.

<%= image_tag @photo.image.url(disposition: :attachment) %>


Run test

$ bin/test test/activestorage_aliyun_test.rb
# run a line
$ bin/test test/activestorage_aliyun_test.rb:129


The gem is available as open source under the terms of the MIT License.

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
ruby (12,918
rails (669
aliyun (53