翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
高度な使用法
このセクションでは、S3 Transfer Manager の高度な使用パターンとテクニックについて説明します。
マルチパートアップロード
S3 Transfer Manager は、大きなファイルに対してマルチパートアップロードを自動的に使用します。この動作は、設定オプションを使用してカスタマイズできます。
<?php use Aws\S3\S3Transfer\Models\UploadRequest; use Aws\S3\S3Transfer\S3TransferManager; require __DIR__ . '/../vendor/autoload.php'; $transferManager = new S3TransferManager(null, []); $uploadPromise = $transferManager->upload( new UploadRequest( '/path/to/large/file.mp4', [ 'Bucket' => 'amzn-s3-demo-bucket', 'Key' => 'videos/large-file.mp4', ], [ // Use multipart upload for files larger than 100MB. 'multipart_upload_threshold_bytes' => 100 * 1024 * 1024, // Use 25MB parts for multipart uploads. 'target_part_size_bytes' => 25 * 1024 * 1024, ] ) ); $uploadPromise->wait();
マルチパートダウンロード
マルチパートダウンロードの動作をカスタマイズできます。
<?php use Aws\S3\S3Transfer\AbstractMultipartDownloader; use Aws\S3\S3Transfer\Models\DownloadRequest; use Aws\S3\S3Transfer\S3TransferManager; require __DIR__ . '/../vendor/autoload.php'; $transferManager = new S3TransferManager(null, []); $downloadPromise = $transferManager->download( new DownloadRequest( 's3://amzn-s3-demo-bucket/large-file.mp4', [], [ // Use 25MB parts for multipart downloads. 'target_part_size_bytes' => 25 * 1024 * 1024, // Use ranged-based download instead of part-based. 'multipart_download_type' => AbstractMultipartDownloader::RANGED_GET_MULTIPART_DOWNLOADER, ] ) ); $downloadPromise->wait();
AbstractMultipartDownloader クラスの他のメンバーの詳細については、 API ドキュメント<add link>を参照してください。
カスタムフィルター
フィルター関数を使用して、ディレクトリオペレーション用のファイルを選択的にアップロードまたはダウンロードできます。
ディレクトリフィルターをアップロードする
パラメータ情報の詳細については、 uploadDirectoryメソッドのフィルター呼び出し可能オプションを参照してください。
<?php use Aws\S3\S3Transfer\Models\UploadDirectoryRequest; use Aws\S3\S3Transfer\S3TransferManager; require __DIR__ . '/../vendor/autoload.php'; $transferManager = new S3TransferManager(null, []); // Upload files modified in the last 24 hours. $uploadDirPromise = $transferManager->uploadDirectory( new UploadDirectoryRequest( '/path/to/directory', 'amzn-s3-demo-bucket', [], [ 'filter' => function ($file) { $modTime = filemtime($file); return (time() - $modTime) < 86400; // 24 hours }, ] ) ); $uploadDirPromise->wait();
ディレクトリフィルターをダウンロードする
パラメータ情報の詳細については、 downloadDirectoryメソッドのフィルター呼び出し可能オプションを参照してください。
<?php use Aws\S3\S3Transfer\Models\DownloadDirectoryRequest; use Aws\S3\S3Transfer\S3TransferManager; require __DIR__ . '/../vendor/autoload.php'; $transferManager = new S3TransferManager(null, []); // Download files with a specific prefix. $downloadDirPromise = $transferManager->downloadDirectory( new DownloadDirectoryRequest( 'amzn-s3-demo-bucket', '/path/to/directory', [], [ 'filter' => function ($key) { return strpos($key, 'reports/2023/') === 0; }, ] ) ); $downloadDirPromise->wait();
リクエスト前のコールバック
リクエスト前のコールバックを使用して、各ファイルのリクエストパラメータを変更できます。パラメータの詳細については、以下を参照してください。
-
uploadDirectoryメソッドの put_object_request_callaback 呼び出し可能なオプション -
downloadDirectoryメソッドの download_object_request_modifier 呼び出し可能オプション
例 uploadDirectory メソッドのリクエスト前コールバックの
<?php use Aws\S3\S3Transfer\Models\UploadDirectoryRequest; use Aws\S3\S3Transfer\S3TransferManager; require __DIR__ . '/../vendor/autoload.php'; $transferManager = new S3TransferManager(null, []); // Set custom metadata for each uploaded file. $uploadDirPromise = $transferManager->uploadDirectory( new UploadDirectoryRequest( '/path/to/directory', 'amzn-s3-demo-bucket', [], [ 'upload_object_request_modifier' => function ($args) { $extension = pathinfo($args['Key'], PATHINFO_EXTENSION); switch ($extension) { case 'jpg': case 'jpeg': $args['ContentType'] = 'image/jpeg'; break; case 'png': $args['ContentType'] = 'image/png'; break; case 'pdf': $args['ContentType'] = 'application/pdf'; break; } $args['Metadata'] = [ 'uploaded_at' => date('Y-m-d H:i:s'), ]; }, ] ) ); $uploadDirPromise->wait();