PROFESSIONAL-CLOUD-DEVELOPER · Question #181
You are developing an application that needs to store files belonging to users in Cloud Storage. You want each user to have their own subdirectory in Cloud Storage. When a new user is created, the…
The correct answer is A. Create an object with the name of the subdirectory ending with a trailing slash ('/') that is zero. Cloud Storage is a flat object store - it has no real directory hierarchy. The conventional way to simulate a directory is to create a zero-byte object whose name ends with a trailing slash ('/'), e.g., users/alice/. Most GCP tools (Console, gsutil, client libraries) recognize…
Question
You are developing an application that needs to store files belonging to users in Cloud Storage. You want each user to have their own subdirectory in Cloud Storage. When a new user is created, the corresponding empty subdirectory should also be created. What should you do?
Options
- ACreate an object with the name of the subdirectory ending with a trailing slash ('/') that is zero
- BCreate an object with the name of the subdirectory, and then immediately delete the object within
- CCreate an object with the name of the subdirectory that is zero bytes in length and has WRITER
- DCreate an object with the name of the subdirectory that is zero bytes in length. Set the Content-
How the community answered
(34 responses)- A74% (25)
- B9% (3)
- C15% (5)
- D3% (1)
Explanation
Cloud Storage is a flat object store - it has no real directory hierarchy. The conventional way to simulate a directory is to create a zero-byte object whose name ends with a trailing slash ('/'), e.g., users/alice/. Most GCP tools (Console, gsutil, client libraries) recognize this convention and display it as a folder. Option B (create then immediately delete) is nonsensical - deleting the object removes any trace of the directory. Option C incorrectly sets WRITER permissions on an object, which is not how Cloud Storage IAM works and is a security anti-pattern. Option D sets a Content-Type, which is irrelevant to creating a directory placeholder. A zero-byte object with a trailing slash is the correct, widely-used pattern.
Topics
Community Discussion
No community discussion yet for this question.