Upload object to Oracle Storage using put_object in Python

Viewed 1068

I'm trying to upload an object to Oracle Storage with oci-cli library in Python. When I try using command-line:

oci os object put -ns grddddaaaZZ -bn dev.bucket --name processed/2020-11 --file /path/to/my/file/image.tif

I actually get a response like:

Upload ID: 4f...78f0fdc5
Split file into 2 parts for upload.
Uploading object  [------------------------------------]    0%
...

but when I try using the framework:

try:
    namespace = 'grddddaaaZZ'
    bucket = 'dev.bucket'
    object_path = 'processed/2020-11/image.tif'

    with open('/path/to/my/file/image.tif', "rb") as image:
       publish_payload = image.read()

    response = object_storage.put_object(namespace, bucket, object_path, publish_payload)

except (InvalidConfig, BaseConnectTimeout, ConfigFileNotFound, ServiceError) as error:
    logging.error(">>>>>>>> Something went wrong when try to list bucket {} objects. Error {}".
                          format(bucket, error))

the upload does not complete:

...
    response = object_storage.put_object(namespace, bucket, object_path, publish_payload)
  File ".../.venv/lib/python3.8/site-packages/oci/object_storage/object_storage_client.py", line 4113, in put_object
    return self.base_client.call_api(
  File ".../.venv/lib/python3.8/site-packages/oci/base_client.py", line 272, in call_api
    response = self.request(request)
  File ".../.venv/lib/python3.8/site-packages/oci/base_client.py", line 378, in request
    raise exceptions.RequestException(e)
oci.exceptions.RequestException: ('Connection aborted.', timeout('The write operation timed out'))

I thought that it could be the size of file (which is around 208Mb), but in put_object documentation says 5Gb limit. So, I do not think it could be the issue. My last chance would be to use os.system(), but it would not be what I truly want.

Some clue in what could be missing in this second option?

1 Answers

You could try uploading some other data first, to see if it's the payload:

namespace = 'grddddaaaZZ'
bucket_name = 'dev.bucket'
object_name = 'processed/2020-11/test.txt'
test_data = b"Hello, World!"

obj = object_storage.put_object(
    namespace,
    bucket_name,
    object_name,
    my_data)

or you try it without reading the file contents and just passing the file object:

namespace = 'grddddaaaZZ'
bucket = 'dev.bucket'
object_path = 'processed/2020-11/image.tif'

with open('/path/to/my/file/image.tif', 'rb') as f:
    obj = object_storage.put_object(namespace, bucket, object_path, f)
Related