Interface S3ClientInterface
- Aws\S3\S3ClientInterface implements Aws\AwsClientInterface
- Namespace: Aws\S3
- Located at S3/S3ClientInterface.php
Represents an AWS client.
Direct known implementers
Methods Summary
-
createPresignedRequest ( Aws\CommandInterface $command, int|string|\DateTimeInterface $expires, array $options = [] )
Create a pre-signed URL for the given S3 command object.
-
getObjectUrl ( string $bucket, string $key )
Returns the URL to an object identified by its bucket and key.
- doesBucketExist ( string $bucket )
-
doesBucketExistV2 ( string $bucket, bool $accept403 )
Determines whether or not a bucket exists by name. This method uses S3's HeadBucket operation and requires the relevant bucket permissions in the default case to prevent errors.
- doesObjectExist ( string $bucket, string $key, array $options = [] )
-
doesObjectExistV2 ( string $bucket, string $key, bool $includeDeleteMarkers = false, array $options = [] )
Determines whether or not an object exists by name. This method uses S3's HeadObject operation and requires the relevant bucket and object permissions to prevent errors.
-
registerStreamWrapper ( )
Register the Amazon S3 stream wrapper with this client instance.
-
registerStreamWrapperV2 ( )
Registers the Amazon S3 stream wrapper with this client instance.
-
deleteMatchingObjects ( string $bucket, string $prefix = '', string $regex = '', array $options = [] )
Deletes objects from Amazon S3 that match the result of a ListObjects operation. For example, this allows you to do things like delete all objects that match a specific key prefix.
-
deleteMatchingObjectsAsync ( string $bucket, string $prefix = '', string $regex = '', array $options = [] )
Deletes objects from Amazon S3 that match the result of a ListObjects operation. For example, this allows you to do things like delete all objects that match a specific key prefix.
-
upload ( string $bucket, string $key, mixed $body, string $acl = 'private', array $options = [] )
Upload a file, stream, or string to a bucket.
-
uploadAsync ( string $bucket, string $key, mixed $body, string $acl = 'private', array $options = [] )
Upload a file, stream, or string to a bucket asynchronously.
-
copy ( string $fromBucket, string $fromKey, string $destBucket, string $destKey, string $acl = 'private', array $options = [] )
Copy an object of any size to a different location.
-
copyAsync ( string $fromBucket, string $fromKey, string $destBucket, string $destKey, string $acl = 'private', array $options = [] )
Copy an object of any size to a different location asynchronously.
-
uploadDirectory ( string $directory, string $bucket, string $keyPrefix = null, array $options = [] )
Recursively uploads all files in a given directory to a given bucket.
-
uploadDirectoryAsync ( string $directory, string $bucket, string $keyPrefix = null, array $options = [] )
Recursively uploads all files in a given directory to a given bucket.
-
downloadBucket ( string $directory, string $bucket, string $keyPrefix = '', array $options = [] )
Downloads a bucket to the local filesystem
-
downloadBucketAsync ( string $directory, string $bucket, string $keyPrefix = '', array $options = [] )
Downloads a bucket to the local filesystem
-
determineBucketRegion ( string $bucketName )
Returns the region in which a given bucket is located.
-
determineBucketRegionAsync ( string $bucketName )
Returns a promise fulfilled with the region in which a given bucket is located.
Methods inherited from Aws\AwsClientInterface
Methods Details
Psr\Http\Message\RequestInterface
createPresignedRequest (
Aws\CommandInterface
$command,
integer|string|DateTimeInterface
$expires,
array
$options = []
)
Create a pre-signed URL for the given S3 command object.
Parameters
Aws\CommandInterface |
$command | Command to create a pre-signed URL for. |
integer|string|DateTimeInterface | $expires | The time at which the URL should expire. This can be a Unix timestamp, a PHP DateTime object, or a string that can be evaluated by strtotime(). |
array | $options = [] |
Returns
Psr\Http\Message\RequestInterface |
string getObjectUrl ( string $bucket, string $key )
Returns the URL to an object identified by its bucket and key.
The URL returned by this method is not signed nor does it ensure that the bucket and key given to the method exist. If you need a signed URL, then use the \Aws\S3\S3Client::createPresignedRequest method and get the URI of the signed request.
Parameters
string | $bucket | The name of the bucket where the object is located |
string | $key | The key of the object |
Returns
string The URL to the object |
boolean doesBucketExist ( string $bucket )
Deprecated
Use doesBucketExistV2() instead
Determines whether or not a bucket exists by name.
Parameters
string | $bucket | The name of the bucket |
Returns
boolean |
boolean doesBucketExistV2 ( string $bucket, boolean $accept403 )
Determines whether or not a bucket exists by name. This method uses S3's HeadBucket operation and requires the relevant bucket permissions in the default case to prevent errors.
Parameters
string | $bucket | The name of the bucket |
boolean | $accept403 | Set to true for this method to return true in the case of invalid bucket-level permissions. Credentials MUST be valid to avoid inaccuracies. Using the default value of false will cause an exception to be thrown instead. |
Returns
boolean |
Exceptions
Aws\S3\Exception\S3Exception |Exceptionif there is an unhandled exception |
boolean doesObjectExist ( string $bucket, string $key, array $options = [] )
Deprecated
Use doesObjectExistV2() instead
Determines whether or not an object exists by name.
Parameters
string | $bucket | The name of the bucket |
string | $key | The key of the object |
array | $options = [] | Additional options available in the HeadObject operation (e.g., VersionId). |
Returns
boolean |
boolean doesObjectExistV2 ( string $bucket, string $key, boolean $includeDeleteMarkers = false, array $options = [] )
Determines whether or not an object exists by name. This method uses S3's HeadObject operation and requires the relevant bucket and object permissions to prevent errors.
Parameters
string | $bucket | The name of the bucket |
string | $key | The key of the object |
boolean | $includeDeleteMarkers = false | Set to true to consider delete markers existing objects. Using the default value of false will ignore delete markers and return false. |
array | $options = [] | Additional options available in the HeadObject operation (e.g., VersionId). |
Returns
boolean |
Exceptions
Aws\S3\Exception\S3Exception |Exceptionif there is an unhandled exception |
registerStreamWrapper ( )
Register the Amazon S3 stream wrapper with this client instance.
registerStreamWrapperV2 ( )
Registers the Amazon S3 stream wrapper with this client instance.
This version uses doesObjectExistV2 and doesBucketExistV2 to check resource existence.
deleteMatchingObjects ( string $bucket, string $prefix = '', string $regex = '', array $options = [] )
Deletes objects from Amazon S3 that match the result of a ListObjects operation. For example, this allows you to do things like delete all objects that match a specific key prefix.
Parameters
string | $bucket | Bucket that contains the object keys |
string | $prefix = '' | Optionally delete only objects under this key prefix |
string | $regex = '' | Delete only objects that match this regex |
array | $options = [] | Aws\S3\BatchDelete options array. |
Exceptions
RuntimeException if no prefix and no regex is given |
See
GuzzleHttp\Promise\PromiseInterface
deleteMatchingObjectsAsync (
string
$bucket,
string
$prefix = '',
string
$regex = '',
array
$options = []
)
Deletes objects from Amazon S3 that match the result of a ListObjects operation. For example, this allows you to do things like delete all objects that match a specific key prefix.
Parameters
string | $bucket | Bucket that contains the object keys |
string | $prefix = '' | Optionally delete only objects under this key prefix |
string | $regex = '' | Delete only objects that match this regex |
array | $options = [] | Aws\S3\BatchDelete options array. |
Returns
GuzzleHttp\Promise\PromiseInterface A promise that is settled when matching objects are deleted. |
See
Aws\ResultInterface
upload (
string
$bucket,
string
$key,
mixed
$body,
string
$acl = 'private',
array
$options = []
)
Upload a file, stream, or string to a bucket.
If the upload size exceeds the specified threshold, the upload will be performed using concurrent multipart uploads.
The options array accepts the following options:
- before_upload: (callable) Callback to invoke before any upload operations during the upload process. The callback should have a function signature like
function (Aws\Command $command) {...}
. - concurrency: (int, default=int(3)) Maximum number of concurrent
UploadPart
operations allowed during a multipart upload. - mup_threshold: (int, default=int(16777216)) The size, in bytes, allowed before the upload must be sent via a multipart upload. Default: 16 MB.
- params: (array, default=array([])) Custom parameters to use with the upload. For single uploads, they must correspond to those used for the
PutObject
operation. For multipart uploads, they correspond to the parameters of theCreateMultipartUpload
operation. - part_size: (int) Part size to use when doing a multipart upload.
Parameters
string | $bucket | Bucket to upload the object. |
string | $key | Key of the object. |
mixed | $body | Object data to upload. Can be a StreamInterface, PHP stream resource, or a string of data to upload. |
string | $acl = 'private' | ACL to apply to the object (default: private). |
array | $options = [] | Options used to configure the upload process. |
Returns
Aws\ResultInterface Returns the result of the upload. |
See
GuzzleHttp\Promise\PromiseInterface
uploadAsync (
string
$bucket,
string
$key,
mixed
$body,
string
$acl = 'private',
array
$options = []
)
Upload a file, stream, or string to a bucket asynchronously.
Parameters
string | $bucket | Bucket to upload the object. |
string | $key | Key of the object. |
mixed | $body | Object data to upload. Can be a StreamInterface, PHP stream resource, or a string of data to upload. |
string | $acl = 'private' | ACL to apply to the object (default: private). |
array | $options = [] | Options used to configure the upload process. |
Returns
GuzzleHttp\Promise\PromiseInterface Returns a promise that will be fulfilled with the result of the upload. |
See
Aws\ResultInterface
copy (
string
$fromBucket,
string
$fromKey,
string
$destBucket,
string
$destKey,
string
$acl = 'private',
array
$options = []
)
Copy an object of any size to a different location.
If the upload size exceeds the maximum allowable size for direct S3 copying, a multipart copy will be used.
The options array accepts the following options:
- before_upload: (callable) Callback to invoke before any upload operations during the upload process. The callback should have a function signature like
function (Aws\Command $command) {...}
. - concurrency: (int, default=int(5)) Maximum number of concurrent
UploadPart
operations allowed during a multipart upload. - params: (array, default=array([])) Custom parameters to use with the upload. For single uploads, they must correspond to those used for the
CopyObject
operation. For multipart uploads, they correspond to the parameters of theCreateMultipartUpload
operation. - part_size: (int) Part size to use when doing a multipart upload.
Parameters
string | $fromBucket | Bucket where the copy source resides. |
string | $fromKey | Key of the copy source. |
string | $destBucket | Bucket to which to copy the object. |
string | $destKey | Key to which to copy the object. |
string | $acl = 'private' | ACL to apply to the copy (default: private). |
array | $options = [] | Options used to configure the upload process. |
Returns
Aws\ResultInterface Returns the result of the copy. |
See
GuzzleHttp\Promise\PromiseInterface
copyAsync (
string
$fromBucket,
string
$fromKey,
string
$destBucket,
string
$destKey,
string
$acl = 'private',
array
$options = []
)
Copy an object of any size to a different location asynchronously.
Parameters
string | $fromBucket | Bucket where the copy source resides. |
string | $fromKey | Key of the copy source. |
string | $destBucket | Bucket to which to copy the object. |
string | $destKey | Key to which to copy the object. |
string | $acl = 'private' | ACL to apply to the copy (default: private). |
array | $options = [] | Options used to configure the upload process. |
Returns
GuzzleHttp\Promise\PromiseInterface Returns a promise that will be fulfilled with the result of the copy. |
See
uploadDirectory ( string $directory, string $bucket, string $keyPrefix = null, array $options = [] )
Recursively uploads all files in a given directory to a given bucket.
Parameters
string | $directory | Full path to a directory to upload |
string | $bucket | Name of the bucket |
string | $keyPrefix = null | Virtual directory key prefix to add to each upload |
array | $options = [] | Options available in Aws\S3\Transfer::__construct |
See
GuzzleHttp\Promise\PromiseInterface
uploadDirectoryAsync (
string
$directory,
string
$bucket,
string
$keyPrefix = null,
array
$options = []
)
Recursively uploads all files in a given directory to a given bucket.
Parameters
string | $directory | Full path to a directory to upload |
string | $bucket | Name of the bucket |
string | $keyPrefix = null | Virtual directory key prefix to add to each upload |
array | $options = [] | Options available in Aws\S3\Transfer::__construct |
Returns
GuzzleHttp\Promise\PromiseInterface A promise that is settled when the upload is complete. |
See
downloadBucket ( string $directory, string $bucket, string $keyPrefix = '', array $options = [] )
Downloads a bucket to the local filesystem
Parameters
string | $directory | Directory to download to |
string | $bucket | Bucket to download from |
string | $keyPrefix = '' | Only download objects that use this key prefix |
array | $options = [] | Options available in Aws\S3\Transfer::__construct |
GuzzleHttp\Promise\PromiseInterface
downloadBucketAsync (
string
$directory,
string
$bucket,
string
$keyPrefix = '',
array
$options = []
)
Downloads a bucket to the local filesystem
Parameters
string | $directory | Directory to download to |
string | $bucket | Bucket to download from |
string | $keyPrefix = '' | Only download objects that use this key prefix |
array | $options = [] | Options available in Aws\S3\Transfer::__construct |
Returns
GuzzleHttp\Promise\PromiseInterface A promise that is settled when the download is complete. |
string determineBucketRegion ( string $bucketName )
Returns the region in which a given bucket is located.
Parameters
string | $bucketName |
Returns
string |
GuzzleHttp\Promise\PromiseInterface
determineBucketRegionAsync (
string
$bucketName
)
Returns a promise fulfilled with the region in which a given bucket is located.
Parameters
string | $bucketName |
Returns
GuzzleHttp\Promise\PromiseInterface |