第 7 章 将文件上传到存储桶
要从工作台上传文件到存储桶,请使用 upload_file () 方法。
先决条件
-
您已将
odh-doc-examples存储库克隆到工作台中。 -
您已在工作台中打开
s3client_examples.ipynb文件。 - 已安装 Boto3 并配置了 S3 客户端。
- 您已导入要上传到对象存储的文件到工作台中。
流程
在 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>')将
<file_name> , <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'])您上传的文件将显示在输出中。