这是在目录(S3 存储桶)中创建文件(S3 对象)的 Fog 演练:
connection = Fog::Storage.new({
:provider => 'AWS',
:aws_access_key_id => YOUR_AWS_ACCESS_KEY_ID,
:aws_secret_access_key => YOUR_AWS_SECRET_ACCESS_KEY
})
directory = connection.directories.create(
:key => "fog-demo-#{Time.now.to_i}", # globally unique name
:public => true
)
file = directory.files.create(
:key => 'resume.html',
:body => File.open("/path/to/my/resume.html"),
:public => true
)
但在我看来,这似乎需要 2 个 API 调用:
connection.directories.create
directory.files.create
如果我已经创建了目录(一个 S3 存储桶),我如何创建一个只有一个 Fog 调用的文件(一个 S3 对象)?