You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Active Storage在上传至S3(Scaleway)时指定存储类?

配置Active Storage上传Scaleway S3时设置storage_class

方式一:全局默认配置(修改config/storage.yml)

Scaleway对象存储兼容S3协议,直接使用Active Storage的S3适配器,在配置中添加storage_class参数指定默认存储类:

scaleway_s3:
  service: S3
  access_key_id: <%= Rails.application.credentials.scaleway[:access_key_id] %>
  secret_access_key: <%= Rails.application.credentials.scaleway[:secret_access_key] %>
  region: fr-par  # 替换为你的Scaleway区域,比如nl-ams、pl-waw
  bucket: your-bucket-name  # 替换为你的存储桶名称
  endpoint: https://s3.fr-par.scw.cloud  # 对应区域的S3端点
  storage_class: STANDARD  # Scaleway支持的存储类:STANDARD、ONEZONE_IA、GLACIER_IR等

之后在config/environments/production.rb中指定使用该服务:

config.active_storage.service = :scaleway_s3

方式二:动态指定存储类(针对单个附件)

如果需要给不同附件设置不同存储类,可在上传时直接传入storage_class参数:

# 模型示例
class Document < ApplicationRecord
  has_one_attached :file
end

# 上传时指定存储类
document = Document.new
document.file.attach(
  io: File.open('/path/to/file.pdf'),
  filename: 'report.pdf',
  content_type: 'application/pdf',
  service: :scaleway_s3,
  storage_class: 'GLACIER_IR'  # 按需替换为目标存储类
)

注意事项

  • 确认Scaleway当前支持的存储类,避免传入无效值;
  • 存储类参数会直接传递给AWS SDK,确保你的Rails版本(Active Storage)支持该参数传递(Rails 6.0+基本都支持)。

内容的提问来源于stack exchange,提问作者Mark Robinson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 12:52:07