Spe*_*ley 5 ruby amazon-s3 amazon-web-services
我正在尝试使用ruby aws-sdk gem将整个目录上传到s3.我首先尝试将其分解为较小的问题,因此我目前要做的只是创建一个文件夹,然后将文件放在该文件夹中.我知道技术上s3没有文件夹,而是对象.我知道你可以拥有类似目录的结构.我找不到任何关于如何在线进行此操作的内容,除了使用AWS :: S3 :: Tree阅读之外,文档还没有提及很多关于目录结构的内容
这是我当前尝试创建文件夹然后将文件添加到该文件夹:
#created an object called test
obj = bucket.objects.create('test', 'data')
#this is the path to a css file that I am uploading.
path_to_file = './directory/mobile/player.css'
#writing file to test object
obj.write(Pathname.new(path_to_file))
Run Code Online (Sandbox Code Playgroud)
这实际上做的是编写css文件进行测试.我想要它做的是在名为test的文件夹中创建一个css文件.
我确信我误解了对象与目录的关联方式.任何人都可以发现我出错的地方或指向正确的方向吗?
小智 1
您可以使用以下代码:
# Instantiate the S3 client with your AWS credentials
s3 = AWS::S3.new(
:access_key_id => 'Aws_Access_Key',
:secret_access_key => 'Aws_Secret_Key'
)
# If you want to create bucket
# bucketName: name of the bucket
bucket = s3.buckets.create('bucketName', :acl => :public_read)
# push file to s3
# bucketName: Amazon Bucket Name
# key: The file location that you want to create for your file.
# e.g, key = "user/appName/myapp.zip"
# File_To_Save: The location of your file.
obj = bucket.objects['key']
obj.write(:file => file_name)
puts obj.public_url
# This key describes the directory structure for your file
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3598 次 |
| 最近记录: |