Cloud Storage is a service for storing objects like images on [[Google Cloud Platform]]. Objects are stored in buckets. Use a different [[storage and database]] option for structured data like [[Cloud SQL]].
Four options of **storage class** are available:
- **Standard**: best for data that is frequently accessed ("hot" data). Best for temporary storage of intermediate objects that are deleted quickly.
- **Nearline**: lower cost for infrequently accessed data (at most monthly).
- **Coldline**: very low cost for very infrequently accessed data (at most quarterly).
- **Archive**: best for online backup and disaster recovery (access at most annually).
Colder storage options have higher cost of retrieval not necessarily slower retrieval times (contrast with AWS Glacier, for example).
When networking, co-locating storage with compute maximizes performance and minimizes cost.
Cloud Storage is also an option to host a static website, like your blog or portfolio (bonus: use GitHub Actions to automatically deploy updates).
## adding files to a bucket
First install the [[Google Cloud CLI]].
Below is an example of adding a picture to my `ei-dev-assets` bucket in the `assets/` directory and setting it public.
```bash
gsutil cp ~/Pictures/<file_name>.png gs://ei-dev-assets/assets
gsutil acl ch -u AllUsers:R gs://ei-dev-assets/assets/<file_name>.png
```
A bash script can be used to do the same and print the public URL. Add this file to your `~/.bashrc` file.
```bash
upload_gcs () {
local file="$1"
local bucket="ei-dev-assets"
local path="assets"
local name=$(basename "$file")
gsutil cp "$file" "gs://$bucket/$path/$name" \
&& gsutil acl ch -u AllUsers:R "gs://$bucket/$path/$name"
echo "https://storage.googleapis.com/$bucket/$path/$name"
}
```
Run with
```bash
upload_gcs screenshot.png
```