DEV Community

Lucas M. Ríos
Lucas M. Ríos

Posted on

1

How create and upload content in Cloud Storage GCP?

🛢 Simple way to create a bucket in Cloud Storage from GCP.


🔗Related content

You can find repo related in:

🐱‍🏍GitHub

You can connect with me in:

🧬LinkedIn


Resume 🧾

All this blog is using shell.

Using SDK's Google we will use tool to manage Cloud Storage. In this blog we will create a storage and upload content in it.

For more information and potential of this, click here.


Pre-Conditions:

  • You need have installed SDK. You can do that following next steps Note: I set alias to use SDK like msdk. ---

1st - Set a name to bucket ✍️

We assign to a variable the name that will have bucket.

I use following command:

BUCKET_NAME="xlmriosx_bucket"
Enter fullscreen mode Exit fullscreen mode

2nd - Create bucket ✅

Using SDK installed with alias like msdk I use following command to create a bucket:

  • With alias:
mdsk gsutil mb -p $PROJECT_NAME -c $BUCKET_TYPE -l $REGION gs://$BUCKET_NAME
Enter fullscreen mode Exit fullscreen mode
  • Without alias:
docker run --rm --volumes-from gcloud-config gcr.io/google.com/cloudsdktool/cloud-sdk gsutil mb -p $PROJECT_NAME -c $BUCKET_TYPE -l $REGION gs://$BUCKET_NAME
Enter fullscreen mode Exit fullscreen mode

Where:
$PROJECT_NAME -> Is name of the project where you wnat instance a bucket.

$BUCKET_TYPE -> Is type of storage you want, like standard, nearline, coldline, archive.

$REGION -> Region where you want stay your storage bucket.

OUTPUT:

Creating gs://xlmriosx_bucket/...
Enter fullscreen mode Exit fullscreen mode

3rd - Verify that your bucket was created ✅

We will list buckets to verify that our bucket was created:

  • With alias:
docker run -ti --name gcloud-config gcr.io/google.com/cloudsdktool/cloud-sdk gcloud auth login
Enter fullscreen mode Exit fullscreen mode
  • Without alias:
msdk gsutil ls gs://$BUCKET_NAME
Enter fullscreen mode Exit fullscreen mode

4th - Upload content in bucket ⬆️

We can copy content to bucket with the following command:

msdk gsutil cp $DATA gs://$BUCKET_NAME
Enter fullscreen mode Exit fullscreen mode

OUTPUT:

Copying file:///$DATA
[Content-Type=X]...
- [1 files][    Y.0 B/    Y.0 B]
Operation completed over 1 objects/Y.0 B.
Enter fullscreen mode Exit fullscreen mode

Where:
$DATA -> Directory or file that we want upload in the bucket.


5th - Say thanks, give like and share if this has been of help/interest 😁🖖


Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay