第6章 バケットからのファイルのダウンロード
バケットからワークベンチにファイルをダウンロードするには、download_file()
メソッドを使用します。
前提条件
-
odh-doc-examples
リポジトリーをワークベンチにクローンしている。 -
ワークベンチで
s3client_examples.ipynb
ファイルを開いている。 - Boto3 をインストールし、S3 クライアントを設定している。
手順
ノートブックで、次の指示を参照してバケットからファイルをダウンロードします。
#Download file from bucket #Replace the following values with your own: #<bucket_name>: The name of the bucket. #<object_name>: The name of the file to download. Must include full path to the file on the bucket. #<file_name>: The name of the file when downloaded. s3_client.download_file('<bucket_name>','<object_name>','<file_name>')
コードサンプルを変更します。
-
<bucket_name>
を、ファイルが保存されているバケットの名前に置き換えます。<object_name>
をダウンロードするファイルの名前に置き換えます。 例に示すように、
<file_name>
を、ファイルのダウンロード先の名前とパスに置き換えます。s3_client.download_file('aqs086-image-registry', 'series35-image36-086.csv', '\tmp\series35-image36-086.csv_old')
-
- コードセルを実行します。
検証
- ダウンロードしたファイルは、ワークベンチで指定したパスに表示されます。