Organizing Objects Using Folders
In QStorage, objects are the primary resources, and objects are stored in buckets. QStorage buckets have a flat structure instead of a hierarchy like you would see in a file system. However, for organizational simplicity, QStorage supports the concept of folders as a means of grouping objects.
Folders in QStorage work by using a shared name prefix for grouped objects. In other words, the grouped objects have names that begin with a common string. This common string, or shared prefix, is the folder name. Object names are also referred to as key names.
How Folders Work in QStorage
For example, you can create a folder in a bucket named photos
and store an object named myphoto.jpg
in it. The object is then stored with the key name photos/myphoto.jpg
, where photos/
is the prefix.
Here are two more examples:
- If you have three objects in your bucket—
logs/date1.txt
,logs/date2.txt
, andlogs/date3.txt
—QStorage will show a folder namedlogs
. If you open the folder, you will see three objects:date1.txt
,date2.txt
, anddate3.txt
. - If you have an object named
photos/2023/example.jpg
, QStorage shows you a folder namedphotos
that contains the folder2023
. The folder2023
contains the objectexample.jpg
.
You can have folders within folders, but not buckets within buckets. You can upload and copy objects directly into a folder. Folders can be created, deleted, and made public, but they can't be renamed. Objects can be copied from one folder to another.
Important Notes About Folders
When you create a folder in QStorage, the system creates a 0-byte object. This object key is set to the folder name that you provided plus a trailing forward slash (/
) character. For example, if you create a folder named photos
in your bucket, QStorage creates a 0-byte object with the key photos/
. This object is created to support the idea of folders.
Also, any pre-existing object that's named with a trailing forward slash character (/
) appears as a folder in QStorage. For example, an object with the key name examplekeyname/
appears as a folder and not as an object. Otherwise, it behaves like any other object and can be viewed and manipulated through the CLI or API.
Creating a Folder
- Using QConsole
- Using Q's CLI Tooling
- Using a Third-party S3-compatible CLI
- Navigate to the QConsole
- Select the bucket where you want to create a folder
- Click on "Create folder"
- Enter a name for the folder (for example,
documents
) - Click "Create folder"
You can create folders using the CLI by either creating a 0-byte object with a trailing slash or by uploading objects with the folder prefix:
# Create an empty folder
qcli s3api put-object --bucket bucket-name --key folder-name/ --body /dev/null
# Upload an object to a folder (creates the folder if it doesn't exist)
qcli s3api cp /path/to/local/file.txt s3://bucket-name/folder-name/
# Create an empty folder
aws s3api put-object --bucket bucket-name --key folder-name/ --body /dev/null --endpoint-url https://qstorage.quilibrium.com
# Upload an object to a folder (creates the folder if it doesn't exist)
aws s3 cp /path/to/local/file.txt s3://bucket-name/folder-name/ --endpoint-url https://qstorage.quilibrium.com
Making Folders Public
We recommend blocking all public access to your QStorage folders and buckets unless you specifically require a public folder or bucket. When you make a folder public, anyone on the internet can view all the objects that are grouped in that folder.
- Using QConsole
- Using Q's CLI Tooling
- Using a Third-party S3-compatible CLI
- Navigate to the QConsole
- Select the bucket containing the folder you want to make public
- Select the folder
- Click on "Make public"
- Confirm your action
You can make a folder public by setting the ACL for all objects in the folder:
# Make all objects in a folder public
qcli s3api put-object-acl --bucket bucket-name --prefix folder-name/ --acl public-read --recursive
# Make all objects in a folder public
aws s3 cp s3://bucket-name/folder-name/ s3://bucket-name/folder-name/ --acl public-read --recursive --metadata-directive REPLACE --endpoint-url https://qstorage.quilibrium.com
Warning: After you make a folder public, you can't make it private again with a single action. Instead, you must set permissions on each individual object in the public folder so that the objects have no public access.
Calculating Folder Size
- Using QConsole
- Using Q's CLI Tooling
- Using a Third-party S3-compatible CLI
- Navigate to the QConsole
- Select the bucket containing the folder
- Select the checkbox next to the folder name
- Click on "Actions" and select "Calculate total size"
The total size and number of objects will be displayed. Note that this information is only available temporarily and will need to be recalculated if you navigate away from the page.
# List all objects in a folder with their sizes
qcli s3api ls s3://bucket-name/folder-name/ --recursive --human-readable --summarize
# List all objects in a folder with their sizes
aws s3 ls s3://bucket-name/folder-name/ --recursive --human-readable --summarize --endpoint-url https://qstorage.quilibrium.com
Deleting Folders
When you delete a folder, all objects within that folder are also deleted.
- Using QConsole
- Using Q's CLI Tooling
- Using a Third-party S3-compatible CLI
- Navigate to the QConsole
- Select the bucket containing the folder you want to delete
- Select the checkbox next to the folder name
- Click on "Delete"
- Confirm the deletion
# Delete a folder and all its contents
qcli s3api rm s3://bucket-name/folder-name/ --recursive
# Delete a folder and all its contents
aws s3 rm s3://bucket-name/folder-name/ --recursive --endpoint-url https://qstorage.quilibrium.com
Warning: This action deletes all objects in the folder. When deleting folders, wait for the delete action to finish before adding new objects to the folder. Otherwise, new objects might be deleted as well.