CodexBloom - Programming Q&A Platform

OCI Object Storage Upload scenarios with '403 Forbidden' scenarios on Pre-signed URL

πŸ‘€ Views: 4193 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-10
oci object-storage presigned-url python Python

I've been working on this all day and Quick question that's been bugging me - I'm trying to upload files to Oracle Cloud Infrastructure (OCI) Object Storage using pre-signed URLs, but I'm working with a '403 Forbidden' behavior when I attempt the upload. I have generated the pre-signed URL using the OCI SDK for Python (version 2.46.0), and I can confirm that the URL is valid because I'm able to access it via a GET request. However, when I try to perform a PUT request to upload the file using `requests`, it fails with the following behavior: ``` 403 Forbidden: The request you made is not allowed. ``` Here’s the code I'm using to generate the pre-signed URL: ```python import oci # Configuration and client setup config = oci.config.from_file() object_storage_client = oci.object_storage.ObjectStorageClient(config) namespace = object_storage_client.get_namespace().data bucket_name = 'my_bucket' object_name = 'my_file.txt' # Generate pre-signed URL url = object_storage_client.generate_presigned_url( method='PUT', namespace_name=namespace, bucket_name=bucket_name, object_name=object_name, expires_in_seconds=3600 ) print(url) ``` After generating the URL, I attempt to upload a file like this: ```python import requests file_path = 'path/to/my_file.txt' with open(file_path, 'rb') as file: response = requests.put(url, data=file) print(response.status_code, response.text) ``` I double-checked that the file exists and that the permissions on the bucket allow for uploads, but I'm still getting the '403 Forbidden' behavior. I've also verified that the OCI API key and other credentials are correct. Is there something I'm missing in the configuration or the upload process? Any insights would be greatly appreciated! This is part of a larger application I'm building. Am I missing something obvious?