Upload to Object Storage on OCI (Oracle
Cloud Infrastructure) using CLI (Command
Line Interface)
Nikhil Karnik + Follow
Work on the most strategic AWS services, verticals, and customer
segments
Published Feb 17, 2018
In this example I will demonstrate the use of CLI with Object Storage.
Overview : The command line interface (CLI) is a tool that enables you to work
with Oracle Cloud Infrastructure objects and services. The CLI provides much the
same functionality as the Console and includes additional advanced commands.
Some of these commands, such as the ability to run scripts, extend the Console's
functionality.
The following Oracle Cloud Infrastructure services are supported with CLI.
Audit
Core Services (Networking, Compute, Block Volume)
Database
IAM
Object Storage
Load Balancing
DNS
LikeZone Management
Comment Share 80 · 9 Comments
There are different way to upload files to Object Storage and its documented here.
In this blog I demonstrate a working example to use OCI CLI to upload files to
Object Storage.
High level Steps
Install OCI CLI (Automatically Installing CLI & Dependencies with CLI installer)
Configure OCI CLI
Copy Public Key to OCI
Validate CLI installation
Upload files to Object Storage
Step 1 Install CLI (Automatically Installing CLI & Dependencies with CLI
installer)
1. To install the CLI using oracle OS user, I had to add oracle OS use to the
sudoer.
vi /etc/sudoers
Add entry for
## The commands section may have other options added to it.
##
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
oracle ALL=(root) ALL
2. Login as oracle OS user and run the below command to install OCI cli.
(This step will take few minutes)
bash -c "$(curl -L [Link]
cli/master/scripts/install/[Link])"
Step 2 Configure CLI
Before using the CLI, you have to create a config file that contains the required
credentials for working with Oracle Cloud Infrastructure. Login as oracle OS user and
run the below command and follow the prompts.
1. oci setup config
[oracle@finqa ~]$ oci setup config
Enter a location for your config [/home/oracle/.oci/config]:
Enter a user OCID:
[Link].oc1..aaaaaaaawhsfelmwqcenomtokpzvrncgmpd35spfere5yzizsb3gcjk5vla
Enter a tenancy OCID:
[Link].oc1..aaaaaaaafwzll3j5n44mksfxlcyywbaur6znkg4chleyozfazsgur65liia
Enter a region (e.g. eu-frankfurt-1, us-ashburn-1, us-phoenix-1): us-phoenix-1
Do you want to generate a new RSA key pair? (If you decline you will be asked to
supply the path to an existing key.) [Y/n]: y
Enter a directory for your keys to be created [/home/oracle/.oci]:
Enter a name for your key [oci_api_key]:
Public key written to: /home/oracle/.oci/oci_api_key_public.pem
Enter a passphrase for your private key (empty for no passphrase):
Private key written to: /home/oracle/.oci/oci_api_key.pem
Fingerprint: [Link]
Config written to /home/oracle/.oci/config
[oracle@finqa ~]$
How to get the OCID for User & OCID for Tenancy
User OCID Click on User at top Right --> User Settings --> User Information --
> OCID
Tenancy OCID Click on Tenancy Name at Top Left à OCID
Region Displayed at the top Left.
Step 3 Copy Public Key to OCI
In the previous step the Public Key that’s generated should be upload to OCI.
/home/oracle/.oci/oci_api_key_public.pem
1. You need to login to Oracle OCI console.
2. On top Right click on User Name --> User Settings --> API Keys --> Add
Public Key
3. Copy the Public Key in the box & click Add.
Step 4 Validate CLI installation
Let’s validate OCI install/configuration using the command which finds the
namespace. Command to find Namespace is --> oci os ns get
[oracle@finqa ~]$ oci os ns get
"data": "gsebmcs00026"
[oracle@finqa ~]$
You can see a valid JSON response which returns a namespace.
Step 5 Upload Files to Object Storage
I have already created a bucket named ADWC. So let’s upload to this bucket.
-ns is the namespace which we got in the previous step
-bn is the bucket name
--name is the name of the file that you would like to see in object storage
--file is the source file name with full path
[oracle@finqa tmp]$ oci os object put -ns gsebmcs00026 -bn ADWC --name
PRODUCTS_DATA_TABLE.dsv --file /tmp/PRODUCTS_DATA_TABLE.dsv
Uploading object [####################################] 100%
"etag": "610A8776E3E3AC24E053824711AC86EC",
"last-modified": "Sat, 23 Dec 2017 [Link] GMT",
"opc-content-md5": "y+rUMMEDFOtRt1wSMnttOg=="
[oracle@finqa tmp]$
Additional commands for reference:
Get the OCID for the compartment --> Identity --> Compartments --> Its will list
all the compartments, find the OCID for the compartment which you have access.
List all Buckets created in compartment
oci os bucket list -ns gsebmcs00026 --compartment-id
[Link].oc1..aaaaaaaa3evaydxyb4gvdti2i4yjzdssr6lauqxzhdh2pzzglfzam
54jm6q
List objects in the Bucket
oci os object list -ns gsebmcs00026 -bn ADWC
Emanuel Jesus Rodríguez 1mo
Professional developer
Gracias por esta información, fue útil y muy bien explicada.
Like · Reply
Matias Choulet 4mo
Jefe de Departamento de Infraestructura IT en Laboratorios Bagó
Muchas gracias, me fui muy útil.
Like · Reply
Iliya Fadeev 5mo
Linux system administrator, sysops engineer, system engineer
Thank you! This helped^_^
Like · Reply
Dhiraj Goundgave 2y
Senior QA Engineer at Quick Heal Technologies
Thank you so much! This helped.
Like · Reply 1 Reaction
Bhoodev Sharma 4y
Leader Digital Transformation & Cloud Security
2GB
Like · Reply
See more comments
To view or add a comment, sign in
More articles by this author
Is Running Count(*) The Only Active Everywhere REST API to scale up/d
Expensive on Cassandra? Database for Hybrid Cloud. the Autonomous Data
Feb 4, 2020 Apr 8, 2019 Jul 16, 2018
See all
Others also viewed
Oracle Fusion Cloud to Data Warehouse-Exporting large volume of data out of
Oracle Cloud using BI Cloud Connector
Prateek Parasar · 3y
Use Data Pump on OCI Cloud Console to Move Data Between Autonomous
Databases
Kurt Liu · 8mo
How to Sync AWS S3 Buckets with Local Folders Let see the steps below
AMIT KUMAR · 1y
OCI Cloud Shell now supports File Upload/Download
Pankaj Mathur · 2y
Using Terraform on Oracle Cloud Infrastructure (OCI)
Cagatay Cebi · 2y
Install OCI-CLI quick setp-by-step guide
Thiago Lemos · 4y
How to import data to Oracle Autonomous database using SQL developer (data
pump)
Bilegt Bat-Ochir · 4y
5 Disruptive Fintech Initiatives in Pakistan
Future Fest · 1mo
Simple Way to Calculate OS CPU Utilization From Oracle Database V$ Views
Craig Shallahamer · 6y
Strategy to Migrate Large Oracle Database from On-premise to Autonomous
Database
Muhammad Shuja (Trusted Advisor) · 6mo
Explore topics
Marketing
Public Administration
Healthcare
Engineering
IT Services
Sustainability
Business Administration
See All
© 2023 About
Accessibility User Agreement
Privacy Policy Cookie Policy
Copyright Policy Brand Policy
Guest Controls Community Guidelines
Language