image

Ishaan

Setup GCP Cloud Storage

To use Google Cloud Storage, change the FILE_STORAGE_PROVIDER variable fo the backend/.env file to use gcp.

FILE_STORAGE_PROVIDER = "gcp"

Go to https://cloud.google.com/ and create an account.Create a new project for the development environment.Go to Storage > Browser and create a new Bucket.Save the bucket name on the FILE_STORAGE_BUCKET variable. The value must be your bucket-name.

In the example of this image, it will be fab-builder.appspot.com.

FILE_STORAGE_BUCKET = "fab-builder.appspot.com"

The service key

Now our app needs a service key to be able to access the bucket.Create a service account key that has permission to manage Google Cloud Storage buckets. Follow this: https://cloud.google.com/iam/docs/creating-managing-service-account-keys#creating_service_account_keys.

After you download the JSON file, you will see that it looks like this:

{

"type": "service_account",

"project_id": "...",

"private_key_id": "...",

"private_key": "...",

"client_email": "...",

"client_id": "...",

"auth_uri": "...",

"token_uri": "...",

"auth_provider_x509_cert_url": "...",

"client_x509_cert_url": "..."

}


Now we must place this entire file into a single environment variable.If you use VSCode, you can use the join lines command.Now place this line on


theGOOGLE_CLOUD_PLATFORM_CREDENTIALS variable.

GOOGLE_CLOUD_PLATFORM_CREDENTIALS = { "type": "service_account", "project_id": "...", "private_key_id": "...", "private_key": "...", "client_email": "...", "client_id": "...", "auth_uri": "...", "token_uri": "...", "auth_provider_x509_cert_url": "...", "client_x509_cert_url": "..." }


CORS

Install the https://cloud.google.com/sdk.Sign in to your account by calling gcloud auth login .

Create a gcp-cors.json file on the same folder that you are at the command line

[{

"maxAgeSeconds": 3600,

"method": ["GET", "HEAD", "POST", "PUT"],

"origin": ["*"],

"responseHeader": ["Content-Type", "Access-Control-Allow-Origin"]

}]

Run this script. Make sure you replace the your-bucket-name by the bucket you created!

gsutil cors set gcp-cors.json gs://your-bucket-name

Done! You are now ready to use the Google Cloud File storage on your project.

image

Ishaan

Architect
ishaan@fabbuilder.com

I love finding patterns and concluding insights out of it. After working as Employee, a Consultant, a Freelancer I figured out mostly we start our project or a module or microservice either by copying an existing code or base repositories from GitHub lets say. And then spend a lot of time on customising it, analysing pitfalls, making it work so that I can start wrinting business logic for the work. So, I started POC-ing FAB Builder so that I get a trailered project targetted to my requirements and on which I can start wrinting business logic within few mins. This makes my life easy and my clients get a better quality products which are easy to modify and easy to maintain.