Building Media Gallery using Golang, Python IBM COS SDK

Gaurav
4 min readOct 7, 2021

--

Cloud Storage Introduction:

Cloud storage is a cloud computing model that stores data on the Internet through a cloud computing provider that manages and operates data storage as a service. It’s delivered on-demand with just-in-time capacity and costs and eliminates buying and managing your own data storage infrastructure. This gives you agility, global scale, and durability, with “anytime, anywhere” data access.

We will also try to explore some IBM COS use cases.

Types of Cloud Storage:

Fig. 1

Storage as Service in Cloud

Data Storage as a Service — Object Storage

Fig. 2

Few Examples:

File Storage: SMB ( Samba File Share ) , NFS — Do some kind of file and directory navigation. i.e location will look something similar to smb://path/to/file

Block Storage — SAN. Mounting file system using the mount command. Something like /dev/sda

Steps to create your COS storage (lite plan ) in IBM Cloud.

Step 1. Log in to IBM Cloud and Create Object Storage and few Buckets.

Step 2. use Go lang SDK to create Bucket.

Step 3. Use Python program to upload few images stored in a folder to the bucket.

Step 4. Use Django Program and View the image gallery in Browser.

login to cloud.ibm.com after creating an account and click on create resources (top right corner) as in Fig 3 :

Fig 3

Click on Object Storage as in Fig 4.

Fig 4.

Select Lite Plan which provides you 25GB of free storage.

Fig 5.

In the below figure Fig 4. The access key is apikey and the secret key is resource_instance_id. You can use these access keys and secret keys in your API.

Fig 6. The access key and Secret Key
Fig. 7 Identifying Access Key and Secret Key

The below figure shows the description of various types of access:

Fig. 8

Access the objects using endpoint:

Go to Bucket->Configuration

Fig. 9 Bucket List

Find Public endpoint:

Fig.10 Endpoints

Access object using below:

</endpoint>/<bucketname>/<objectname>

Sample Access Link To Object

s3.us.cloud-object-storage.appdomain.cloud/bktfour/ob-1.png

Bucket Limitations

We can create a maximum of 100 buckets

Go Lang SDK for creating buckets:

Below is the main.go file, that I have used in the root directory of the above project.

Execute the below commands to run the main go code and create the bucket.

go build ./...go run main.go <bucketname>

Python Code for Uploading Images to Bucket:

Usage:

Export your access keys to add in the environment variable

Export your secret keys to add in the environment variable:

export MY_COS_IBM_KEY_TEMP=<your API key from service credentials>export export MY_SVC_IBM_INST_ID_TEMP=<service instance id >python cos_api.py <foldername> <bucketname>

e.g. python cos_api.py /Users/images mytestbucket

Python Code for Uploading Objects to IBM CoS Bucket.

Below is the GitHub link for the Django UI for Media gallery:

Follow the README instruction to run your app:

Open the URL. i.e HTTP://127.0.0.1:8000 in the browser you will get the below image gallery:

Congratulations!! We have created an image gallery using IBM COS.

Much useful for photographers, OTT platform owners, Social Media.

Fig. 11

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Gaurav
Gaurav

No responses yet

Write a response