7

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')
RoundOutTooSoon
  • 9,821
  • 8
  • 35
  • 52
  • 2
    AFAIK Amazon S3 doesn't have the concept of directories, it's a flat file system. Directories are only presented in the browser UI for convenience. – Leonid Shevtsov Jul 30 '15 at 20:18
  • 1
    Yeah, there are no true directories in S3, just long paths (where in some contexts prefixes delineated by slashes are treated kind-of-like subdirectories). – geemus Aug 03 '15 at 18:35

1 Answers1

7

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
)
abaldwin99
  • 903
  • 1
  • 8
  • 26