第 7 章 将文件上传到存储桶


要从工作台上传文件到存储桶,请使用 upload_file () 方法。

先决条件

  • 您已将 odh-doc-examples 存储库克隆到工作台中。
  • 您已在工作台中打开 s3client_examples.ipynb 文件。
  • 已安装 Boto3 并配置了 S3 客户端。
  • 您已导入要上传到对象存储的文件到工作台中。

流程

  1. 在 Jupyter 笔记本中,找到上传文件到存储桶的说明。

    #Upload file to bucket
    #Replace <file_name>, <bucket_name>, and <object_name> with your values.
    #<file_name>: Name of the file to upload. This value must include the full local path to the file on your workbench.
    #<bucket_name>: The name of the bucket to upload the file to.
    #<object_name>: The full key to use to save the file to the bucket.
    
    s3_client.upload_file('<file_name>', '<bucket_name>', '<object_name>')
  2. <file_name & gt; , <bucket _name> 和 <object_name > 替换为您自己的值,如示例中所示,然后运行代码单元。

    s3_client.upload_file('image-973-series123.csv', 'aqs973-image-registry', '/tmp/image-973-series124.csv')

验证

  • 找到以下说明以列出存储桶中的文件:

    #Upload Verification
    for key in s3_client.list_objects_v2(Bucket='<bucket_name>')['Contents']:
    print(key['Key'])
  • 将 < bucket_name > 替换为存储桶的名称,如示例所示,然后运行代码单元。

    #Upload Verification
    for key in s3_client.list_objects_v2(Bucket='aqs973-image-registry')['Contents']:  print(key['Key'])

    您上传的文件将显示在输出中。

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部