기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
파일 작업
S3 Transfer Manager는 개별 파일을 업로드하고 다운로드하는 방법을 제공합니다.
로컬 파일 업로드
Amazon S3에 파일을 업로드하려면 upload <링크 추가> 메서드를 사용합니다.
<?php use Aws\S3\S3Transfer\Models\UploadRequest; use Aws\S3\S3Transfer\S3TransferManager; require __DIR__ . '/../vendor/autoload.php'; $transferManager = new S3TransferManager(null, [ 'default_region' => 'us-west-2' ]); // Source can be from a local path to a file. $source = '/path/to/local/file.txt'; // Or the source can be an instance of StreamInterface. $source = GuzzleHttp\Psr7\Utils::streamFor('Hello World!'); $uploadPromise = $transferManager->upload( new UploadRequest( $source, [ 'Bucket' => 'amzn-s3-demo-bucket', 'Key' => 'path/to/s3/file.txt', // Additional `putObject` parameters as needed. ], [ // Optional configuration overrides. 'multipart_upload_threshold_bytes' => 100 * 1024 * 1024, // 100MB 'target_part_size_bytes' => 10 * 1024 * 1024, // 10MB 'track_progress' => true, 'request_checksum_calculation' => 'when_required', ] ) ); // The upload is asynchronous, you can wait for it to complete. $result = $uploadPromise->wait(); // Or you can use the promise for more complex workflows. $result = $uploadPromise->then( function ($result) { echo "Upload succeeded!"; }, function ($error) { echo "Upload failed: " . $error->getMessage(); } )->wait();
upload 메서드 파라미터
upload 메서드는 UploadRequest <링크 추가>의 인스턴스를 인수로 수락합니다.
UploadRequest 파라미터
| 파라미터 | Type | 필수 | 설명 |
|---|---|---|---|
|
|
문자열| |
예 |
업로드할 데이터가 포함된 로컬 파일 경로 또는 스트림의 경로입니다. |
|
|
array |
예 |
요청 인수를 업로드합니다(버킷 및 키를 포함해야 함). |
|
|
array |
아니요 |
이 업로드와 관련된 구성 재정의. 구성 옵션에 대한 자세한 내용은 다음 섹션을 참조하세요. |
|
|
array |
아니요 |
이 업로드를 모니터링하기 위한 |
|
|
TransferListener |
아니요 |
이 업로드에 대한 진행률 트래커입니다. |
SDK는 S3 Transfer Manager의 구성에서 기본$config값을 확인합니다.
| 옵션 | Type | 필수 | 설명 |
|---|---|---|---|
|
|
int |
아니요 |
멀티파트 업로드가 트리거될 때의 기본 임계값을 재정의합니다. |
|
|
int |
아니요 |
기본 대상 파트 크기를 바이트 단위로 재정의합니다. |
|
|
bool |
아니요 |
진행 상황 추적을 활성화하는 기본 옵션을 재정의합니다. 이 옵션이 true 이고 progressTracker 파라미터를 제공하지 않으면 SDK는 기본 구현을 사용합니다. |
|
|
int |
아니요 |
동시성의 기본값을 재정의합니다. |
|
|
문자열 |
No |
요청 체크섬 계산을 수행해야 하는지 여부에 대한 기본값을 재정의합니다. |
upload 메서드가 성공적으로 실행되면 UploadResult <링크 추가>를 반환합니다.
S3 객체 다운로드
Amazon S3에서 객체를 다운로드하려면 download <링크 추가> 메서드를 사용합니다.
<?php use Aws\S3\S3Transfer\Models\DownloadRequest; use Aws\S3\S3Transfer\S3TransferManager; require __DIR__ . '/../vendor/autoload.php'; $transferManager = new S3TransferManager(null, [ 'default_region' => 'us-west-2' ]); // Download using an S3 URI. $downloadPromise = $transferManager->download( new DownloadRequest( 's3://amzn-s3-demo-bucket/path/to/s3/file.txt', [ // Additional `getObject` parameters as needed. ], [ // Optional configuration overrides. 'response_checksum_validation' => 'when_required', 'track_progress' => true, 'target_part_size_bytes' => 10 * 1024 * 1024, // 10MB ] ) ); // Wait for the download to complete. $result = $downloadPromise->wait(); // The SDK uses a stream-based download handler by default. $stream = $result->getDownloadDataResult(); // You can either get the content. $content = $stream->getContents(); // Or write the stream to a file. file_put_contents('/path/to/local/file.txt', $stream); // Don't forget to close the stream. $stream->close();
download 메서드 파라미터
download 메서드는 DownloadRequest <링크 추가>의 인스턴스를 인수로 수락합니다.
DownloadRequest 파라미터
| 파라미터 | Type | 필수 | 설명 |
|---|---|---|---|
|
|
string|array| |
아니요 |
S3에서 다운로드할 객체입니다. 이 파라미터를 S3 URI 문자열("s3://amzn-s3-demo-bucket/key"), 버킷 및 키 키가 있는 배열 또는 로 제공할 수 있습니다 |
|
|
array |
아니요 |
객체 요청 인수를 추가로 다운로드합니다. 이 |
|
|
array |
아니요 |
이 다운로드와 관련된 구성 재정의. 구성 옵션에 대한 자세한 내용은 다음 섹션을 참조하세요. |
$downloadHandler |
|
아니요 |
각 객체 청크를 수신하고 다운로드를 관리하는 핸들러입니다.
자체를 구현 |
|
|
|
아니요 |
이 다운로드에 대한 진행률 트래커입니다. |
|
|
|
아니요 |
이 다운로드를 모니터링하기 위한 |
SDK는 S3 Transfer Manager의 구성에서 기본$config값을 확인합니다.
| 옵션 | Type | 필수 | 설명 |
|---|---|---|---|
|
|
문자열 |
No |
기본 멀티파트 다운로드 유형을 재정의합니다. 유효한 값은 'part', 'range'입니다. |
|
|
문자열 |
No |
체크섬 검증을 수행해야 하는지 여부에 대해 전송 관리자 구성에서 확인된 값을 재정의합니다. SDK는 |
|
|
bool |
아니요 |
진행 상황 추적을 활성화하기 위한 기본 옵션을 재정의합니다. 이 옵션이
|
|
|
int |
아니요 |
범위 멀티파트 다운로드에 사용할 바이트 단위의 파트 크기입니다. 이 파라미터를 제공하지 않으면 다운로드는 전송 관리자에 |
download 메서드가 성공적으로 실행되면 DownloadResult <링크 추가>를 반환합니다.
로컬 파일에 S3 객체 다운로드
S3 객체를 로컬 파일로 직접 다운로드하려면 downloadFile 메서드를 사용합니다.
<?php use Aws\S3\S3Transfer\Models\DownloadFileRequest; use Aws\S3\S3Transfer\Models\DownloadRequest; use Aws\S3\S3Transfer\S3TransferManager; require __DIR__ . '/../vendor/autoload.php'; $transferManager = new S3TransferManager(null, [ 'default_region' => 'us-west-2' ]); $downloadFilePromise = $transferManager->downloadFile( new DownloadFileRequest( '/path/to/local/file.txt', // Destination file path. false, // Fail when destination exists. new DownloadRequest( 's3://amzn-s3-demo-bucket/path/to/s3/file.txt', [], // `getObject` request args [ 'track_progress' => true, 'target_part_size_bytes' => 10 * 1024 * 1024, // 10MB parts ] ) ) ); // Wait for download to complete. $result = $downloadFilePromise->wait(); // `getDownloadDataResult()` returns the string for the file path of the downloaded content because // the default `DownloadHandler` used by `downloadFile()` is a file-based handler. echo "File downloaded successfully at {$result->getDownloadDataResult()}!\n";
downloadFile 메서드 파라미터
downloadFile 메서드는의 인스턴스를 인수DownloadFileRequest로 수락합니다.
DownloadFileRequest 파라미터
| 옵션 | Type | 필수 | 설명 |
|---|---|---|---|
|
|
문자열 |
예 |
파일이 저장되는 로컬 경로입니다. |
|
|
bool |
예 |
대상 파일이 이미 있는 경우 실패할지 여부입니다. 이 옵션이 |
|
|
|
예 |
구성된 |
downloadFile 메서드가 성공적으로 실행되면 DownloadResult <링크 추가>를 반환합니다.