- 查看配置
Settings.uploads.object_store
- 加载minio client
require 'fog/aws'
fog_connection = Fog::Storage.new(
provider: 'AWS',
aws_access_key_id: '你的MINIO_ACCESS_KEY',
aws_secret_access_key: '你的MINIO_SECRET_KEY',
region: '<S3 region>',
endpoint: 'http://127.0.0.2:7480',
path_style: true # 需要开启 path_style
)
bucket = fog_connection.directories.get('你的BUCKET_NAME')
- 创建测试文件
require 'tempfile'
temp_file = Tempfile.new(['test_upload', '.txt'])
temp_file.write('这是一个测试文件内容')
temp_file.rewind # 将文件指针移到开头
- 模拟上传到minio
bucket.files.create(
key: file_path,
body: temp_file.read,
public: false
)
- 获取文件
uploaded_file = bucket.files.get(file_path)
uploaded_file.key
uploaded_file.body
- 删除文件
uploaded_file.destroy
- Giltab上传
uploader = FileUploader.new
uploader.store!(temp_file)
puts "上传路径: #{uploader.url}"