使用Python中的put_object将对象上载到Oracle存储

qeeaahzv  于 2022-11-22  发布在  Oracle
关注(0)|答案(2)|浏览(97)

我尝试使用Python中的oci-cli库将对象上载到Oracle Storage。当我尝试使用命令行时:

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

我得到的回答是:

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

但当我尝试使用这个框架时:

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))

上传未完成:

...
    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'))

我以为可能是文件大小的问题(大约是208Mb),但是在put_object文档中说限制是5Gb。所以,我不认为这可能是问题所在。我最后的机会是使用os.system(),但这不是我真正想要的。
第二种选择可能会遗漏什么?

66bbxpm5

66bbxpm51#

您可以先尝试上传一些其他数据,看看它是否是有效负载:

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)

或者尝试不阅读文件内容而只传递file对象:

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)
ttygqcqt

ttygqcqt2#

with open('tomcat_access_log_20221118-231901.log.zip', 'rb') as filePtr:
...     upload_resp = object_storage_client.put_object(nameSpace,bucket_name='my-Test-Bucket',object_name=file_to_upload,put_object_body=filePtr)
  • 注意:要上载的文件= '用于测试的空文件夹/tomcat-admin-server/tomcat_access_log_20221118-231901.log.zip'*

上面的代码卡住了很长一段时间,直到超时结束。但实际上我可以看到文件上传正确。但这个命令卡住了足够长的时间,直到超时...任何想法?

相关问题