Skip to content

Instantly share code, notes, and snippets.

@webgtx
Created January 31, 2023 16:04
Show Gist options
  • Select an option

  • Save webgtx/4f2e1ceac7c39765c6899e397b341924 to your computer and use it in GitHub Desktop.

Select an option

Save webgtx/4f2e1ceac7c39765c6899e397b341924 to your computer and use it in GitHub Desktop.
Simple script for handling data in OCI Bucket
import requests
url = "https://<object-storage-namespace>.compat.objectstorage.<region>.oraclecloud.com/n/<namespace-name>/b/<bucket-name>"
# List objects in the bucket
response = requests.get(url)
if response.status_code == 200:
object_list = response.text.split("\n")
print("Objects in the bucket:")
for obj in object_list:
print("- {}".format(obj))
else:
print("Failed to retrieve object list, status code: {}".format(response.status_code))
# Upload a file to the bucket
file_path = "<path-to-file>"
file_name = "<object-name>"
with open(file_path, "rb") as file:
headers = {
"Content-Type": "application/octet-stream"
}
upload_url = "{}/{}".format(url, file_name)
response = requests.put(upload_url, headers=headers, data=file)
if response.status_code == 201:
print("File uploaded successfully")
else:
print("Failed to upload file, status code: {}".format(response.status_code))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment