Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby Fog gem: how to create sub-directories?

Tags:

ruby

fog

fog-aws

I have

  connection = Fog::Storage.new(fog_config)
  bucket     = connection.directories.get(bucket_name)

Is there a way (documented, non-documented, work-around) for me to create directories inside of this bucket? Something like:

sub_dir_for_user_1 = bucket.create_sub_dir('/user_1_files')
sub_dir_for_user_2 = bucket.create_sub_dir('/user_2_files')
like image 559
RoundOutTooSoon Avatar asked Jul 30 '15 19:07

RoundOutTooSoon


1 Answers

In S3 zero byte files with a trailing slash will create a pseudo-directory. Which will cause folders to appear in the AWS Browser UI.

For fog passing nil into the body argument creates an empty file. So the following code would create a subdirectory...

bucket.files.create(
  key: 'user_1_files/',
  body: nil
)
like image 111
abaldwin99 Avatar answered Oct 18 '22 06:10

abaldwin99