本页还没有译文
本页 5 段还没译成繁體中文,下面显示的是英文原文。aws-sdk-ruby
还没翻译译自英文(developers.cloudflare.com)本页 5 段都还没译
You must generate an Access Key before getting started. All examples will utilize access_key_id and access_key_secret variables which represent the Access Key ID and Secret Access Key values you generated.
Many Ruby projects also store these credentials in environment variables instead.
Add the following dependency to your Gemfile:
gem "aws-sdk-s3"Then you can use Ruby to operate on R2 buckets:
require "aws-sdk-s3"
@r2 = Aws::S3::Client.new(
# Retrieve your S3 API credentials for your R2 bucket via API tokens (see: https://developers.cloudflare.com/r2/api/tokens)
access_key_id: "#{ACCESS_KEY_ID}",
secret_access_key: "#{SECRET_ACCESS_KEY}",
# Provide your Cloudflare account ID
endpoint: "https://#{ACCOUNT_ID}.r2.cloudflarestorage.com",
region: "auto", # Required by SDK but not used by R2
)
# List all buckets on your account
puts @r2.list_buckets
#=> {
#=> :buckets => [{
#=> :name => "your-bucket",
#=> :creation_date => "…",
#=> }],
#=> :owner => {
#=> :display_name => "…",
#=> :id => "…"
#=> }
#=> }
# List the first 20 items in a bucket
puts @r2.list_objects_v2(bucket: "your-bucket", max_keys: 20)
#=> {
#=> :is_truncated => false,
#=> :name => "your-bucket",
#=> :prefix => nil,
#=> :delimiter => nil,
#=> :max_keys => 20,
#=> :common_prefixes => [],
#=> :encoding_type => nil,
#=> :key_count => 3,
#=> :contents => [
#=> …,
#=> …,
#=> …,
#=> ]
#=> }AI 翻译查看英文原文