Last active
April 12, 2023 14:28
-
-
Save josethz00/1878ac3ea94f0c5dd08d3eeeeafca506 to your computer and use it in GitHub Desktop.
Upload files to Oracle Cloud Storage using AWS S3 python SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3, dotenv, os | |
# Load .env file | |
dotenv.load_dotenv() | |
# Oracle Cloud Infrastructure has a compatibility API for S3, so we can use the boto3 library to connect to OCI Object Storage | |
# For more information on the compatibility API, see: https://docs.cloud.oracle.com/en-us/iaas/Content/Object/Tasks/s3compatibleapi.htm | |
# Keep in mind that for the compatibility API to work, you need to do some extra configuration in your OCI Object Storage Bucket | |
s3 = boto3.resource( | |
's3', | |
region_name="<<ADD YOUR ORACLE REGION HERE>>", | |
aws_secret_access_key=os.getenv("OCI_SECRET_ACCESS_KEY"), | |
aws_access_key_id=os.getenv("OCI_ACCESS_KEY_ID"), | |
endpoint_url=f'https://{os.getenv("OCI_STORAGE_NAMESPACE")}.compat.objectstorage.<<ADD YOUR ORACLE REGION HERE>>.oraclecloud.com' | |
) | |
# Upload a File to you OCI Bucket, 1st value is the file name and local path, 2nd value is your bucket name, 3rd value is the file name and path in your bucket | |
s3.meta.client.upload_file('/tmp/hello.txt', '<<YOUR BUCKET NAME>>', 'hello.txt') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment