Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

carrierwave-aliyun

> 后端框架
Open source

阿里云 OSS Ruby 上传组件,基于 Carrierwave

196 stars0 likes1 views
WebsiteGitHub

About

阿里云 OSS Ruby 上传组件,基于 Carrierwave

CarrierWave for Aliyun OSS

This gem adds support for Aliyun OSS to CarrierWave

NOTE: 此 Gem 是一个 CarrierWave 的组件,你需要配合 CarrierWave 一起使用,如果你需要直接用 Aliyun OSS,可以尝试用 aliyun-sdk 这个 Gem。

NOTE: This gem is a extends for CarrierWave for allow it support use Alicloud OSS as storage backend, if you wants use Alicloud OSS directly, please visit aliyun-sdk.

Using Bundler

ruby
gem 'carrierwave-aliyun'

Configuration

You need a config/initializers/carrierwave.rb for initialize, and update your configurations:

…

阿里云 OSS 图片缩略图 / About the image Thumb service for Alicloud OSS

NOTE: 此方法同样支持 Private 的 Bucket 哦!

NOTE: Private Bucket also support this feature!

关于阿里云 OSS 图片缩略图的详细文档,请仔细阅读:Aliyun OSS 接入图片服务

The details of the Alicoud OSS image thumb service, please visit Alicloud OSS - Image Processing / Resize images

rb
irb> User.last.avatar.url(thumb: '?x-oss-process=image/resize,h_100')
"https://simple.oss-cn-hangzhou.aliyuncs.com/users/avatar/12.png?x-oss-process=image/resize,h_100"
irb> User.last.avatar.url(thumb: '?x-oss-process=image/resize,h_100,w_100')
"https://simple.oss-cn-hangzhou.aliyuncs.com/users/avatar/12.png?x-oss-process=image/resize,h_100,w_100"

增对文件设置 Content-Disposition / Customize the Content-Disposition

在文件上传的场景(非图片),你可能需要给上传的文件设置 Content-Disposition 以便于用户直接访问 URL 的时候能够用你期望的文件名或原文件名来下载并保存。

In some case, you may need change the Content-Disposition for your uploaded files for allow users visit URL with direct download, and get the original filename.

这个时候你需要给 Uploader 实现 content_disposition 函数,例如:

So, you need implement a content_disposition method for your CarrierWave Uploader, for example:

rb
# app/uploaders/attachment_uploader.rb
class AttachmentUploader  错误:OSS Transfer Acceleration is not configured on this bucket.
> 确保有开启 [传输加速](https://help.aliyun.com/document_detail/131312.html),进入 Bucket / 传输管理 / 传输加速 / 开启传输加速。

额外注意:Aliyun OSS 开启传输加速后需要 **30 分钟内全网生效**

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubyaliyun-osscarrierwavecarrierwave-pluginsrails

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架