How to create a directory structure using ruby ​​aws-sdk on s3?

I am trying to load the entire directory into s3 using the ruby ​​aws-sdk gem. I first try to break it down into smaller problems, so what I'm trying to do now is just create one folder and then put the file inside this folder. I know that technically s3 does not have folders, but objects. I know you might have a directory-like structure. I can't find anything about how to do this on the Internet, and the docs don't mention much about the directory structure other than reading with AWS :: S3 :: Tree

This is my current attempt to create a folder and then add the file to the folder:

#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)) 

What this actually does is write a css file for testing. I want it to create a css file inside a folder called test.

I am sure I do not understand how objects are related to directories. Can someone determine where I'm going, or point me in the right direction?

+4
source share
1 answer

You can use the following code:

 # 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. # eg, 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 
0
source

Source: https://habr.com/ru/post/1480384/


All Articles