Upload files from autonomous database to object storage - oci

 Pre-requisite:

  •  Get the bucket details where you want to upload the files

    Please refer this API endpoints and choose the one which matches your region.

     [ https://docs.oracle.com/en-us/iaas/api/#/en/objectstorage/20160918/ ] 

  • you need an user and it must have privilege to upload files to the object storage

   [ https://docs.oracle.com/en/cloud/paas/autonomous-database/adbsa/dbms-cloud-subprograms.html#GUID-742FC365-AA09-48A8-922C-1987795CF36A ]

    In my example, I am using apikey added user. [ https://oracle-autonomous-db.blogspot.com/2022/07/user-setup-on-oci-basics-setup-required.html ]

First create the credential in autonomous database. 

Syntax:

BEGIN
   DBMS_CLOUD.CREATE_CREDENTIAL (
       credential_name => ‘OCI_KEY_CRED’,
       user_ocid       => ‘ ’,
       tenancy_ocid    => ‘’,
       private_key     => ‘',
       fingerprint     => ‘’);
END;
/

        Example:


The credential has been created. Now, we will list the credential.

select * from dba_credentials where credential_name like'OBJECT_STORAGE%';

Now list the directory where the files kept.

SELECT * FROM DBMS_CLOUD.LIST_FILES('DATA_PUMP_DIR');


Now upload the files using dbms_cloud.put_file 

Upload the file

BEGIN

   DBMS_CLOUD.PUT_OBJECT(credential_name => 'OBJECT_STORAGE_UPLOAD',

     object_uri => 'https://objectstorage.ap-melbourne-1.oraclecloud.com/n/axatkk9parjt/b/tamil/o/',

     directory_name => 'DATA_PUMP_DIR',

     file_name => 'OML4PY_IMPORT_54.log');

end;

/


Now verify the object in the object storage and it got uploaded. 



















Comments