1 |
efrain |
1 |
<?php
|
|
|
2 |
namespace Aws\S3;
|
|
|
3 |
|
|
|
4 |
use Aws\AwsClientInterface;
|
|
|
5 |
use Aws\CommandInterface;
|
|
|
6 |
use Aws\ResultInterface;
|
|
|
7 |
use Aws\S3\Exception\S3Exception;
|
|
|
8 |
use GuzzleHttp\Promise\PromiseInterface;
|
|
|
9 |
use Psr\Http\Message\RequestInterface;
|
|
|
10 |
|
|
|
11 |
interface S3ClientInterface extends AwsClientInterface
|
|
|
12 |
{
|
|
|
13 |
/**
|
|
|
14 |
* Create a pre-signed URL for the given S3 command object.
|
|
|
15 |
*
|
|
|
16 |
* @param CommandInterface $command Command to create a pre-signed
|
|
|
17 |
* URL for.
|
|
|
18 |
* @param int|string|\DateTimeInterface $expires The time at which the URL should
|
|
|
19 |
* expire. This can be a Unix
|
|
|
20 |
* timestamp, a PHP DateTime object,
|
|
|
21 |
* or a string that can be evaluated
|
|
|
22 |
* by strtotime().
|
|
|
23 |
*
|
|
|
24 |
* @return RequestInterface
|
|
|
25 |
*/
|
|
|
26 |
public function createPresignedRequest(CommandInterface $command, $expires, array $options = []);
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* Returns the URL to an object identified by its bucket and key.
|
|
|
30 |
*
|
|
|
31 |
* The URL returned by this method is not signed nor does it ensure that the
|
|
|
32 |
* bucket and key given to the method exist. If you need a signed URL, then
|
|
|
33 |
* use the {@see \Aws\S3\S3Client::createPresignedRequest} method and get
|
|
|
34 |
* the URI of the signed request.
|
|
|
35 |
*
|
|
|
36 |
* @param string $bucket The name of the bucket where the object is located
|
|
|
37 |
* @param string $key The key of the object
|
|
|
38 |
*
|
|
|
39 |
* @return string The URL to the object
|
|
|
40 |
*/
|
|
|
41 |
public function getObjectUrl($bucket, $key);
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* @deprecated Use doesBucketExistV2() instead
|
|
|
45 |
*
|
|
|
46 |
* Determines whether or not a bucket exists by name.
|
|
|
47 |
*
|
|
|
48 |
* @param string $bucket The name of the bucket
|
|
|
49 |
*
|
|
|
50 |
* @return bool
|
|
|
51 |
*/
|
|
|
52 |
public function doesBucketExist($bucket);
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* Determines whether or not a bucket exists by name. This method uses S3's
|
|
|
56 |
* HeadBucket operation and requires the relevant bucket permissions in the
|
|
|
57 |
* default case to prevent errors.
|
|
|
58 |
*
|
|
|
59 |
* @param string $bucket The name of the bucket
|
|
|
60 |
* @param bool $accept403 Set to true for this method to return true in the case of
|
|
|
61 |
* invalid bucket-level permissions. Credentials MUST be valid
|
|
|
62 |
* to avoid inaccuracies. Using the default value of false will
|
|
|
63 |
* cause an exception to be thrown instead.
|
|
|
64 |
*
|
|
|
65 |
* @return bool
|
|
|
66 |
* @throws S3Exception|\Exception if there is an unhandled exception
|
|
|
67 |
*/
|
|
|
68 |
public function doesBucketExistV2($bucket, $accept403);
|
|
|
69 |
|
|
|
70 |
/**
|
|
|
71 |
* @deprecated Use doesObjectExistV2() instead
|
|
|
72 |
*
|
|
|
73 |
* Determines whether or not an object exists by name.
|
|
|
74 |
*
|
|
|
75 |
* @param string $bucket The name of the bucket
|
|
|
76 |
* @param string $key The key of the object
|
|
|
77 |
* @param array $options Additional options available in the HeadObject
|
|
|
78 |
* operation (e.g., VersionId).
|
|
|
79 |
*
|
|
|
80 |
* @return bool
|
|
|
81 |
*/
|
|
|
82 |
public function doesObjectExist($bucket, $key, array $options = []);
|
|
|
83 |
|
|
|
84 |
/**
|
|
|
85 |
* Determines whether or not an object exists by name. This method uses S3's HeadObject
|
|
|
86 |
* operation and requires the relevant bucket and object permissions to prevent errors.
|
|
|
87 |
*
|
|
|
88 |
* @param string $bucket The name of the bucket
|
|
|
89 |
* @param string $key The key of the object
|
|
|
90 |
* @param bool $includeDeleteMarkers Set to true to consider delete markers
|
|
|
91 |
* existing objects. Using the default value
|
|
|
92 |
* of false will ignore delete markers and
|
|
|
93 |
* return false.
|
|
|
94 |
* @param array $options Additional options available in the HeadObject
|
|
|
95 |
* operation (e.g., VersionId).
|
|
|
96 |
*
|
|
|
97 |
* @return bool
|
|
|
98 |
* @throws S3Exception|\Exception if there is an unhandled exception
|
|
|
99 |
*/
|
|
|
100 |
public function doesObjectExistV2($bucket, $key, $includeDeleteMarkers = false, array $options = []);
|
|
|
101 |
|
|
|
102 |
/**
|
|
|
103 |
* Register the Amazon S3 stream wrapper with this client instance.
|
|
|
104 |
*/
|
|
|
105 |
public function registerStreamWrapper();
|
|
|
106 |
|
|
|
107 |
/**
|
|
|
108 |
* Registers the Amazon S3 stream wrapper with this client instance.
|
|
|
109 |
*
|
|
|
110 |
*This version uses doesObjectExistV2 and doesBucketExistV2 to check
|
|
|
111 |
* resource existence.
|
|
|
112 |
*/
|
|
|
113 |
public function registerStreamWrapperV2();
|
|
|
114 |
|
|
|
115 |
/**
|
|
|
116 |
* Deletes objects from Amazon S3 that match the result of a ListObjects
|
|
|
117 |
* operation. For example, this allows you to do things like delete all
|
|
|
118 |
* objects that match a specific key prefix.
|
|
|
119 |
*
|
|
|
120 |
* @param string $bucket Bucket that contains the object keys
|
|
|
121 |
* @param string $prefix Optionally delete only objects under this key prefix
|
|
|
122 |
* @param string $regex Delete only objects that match this regex
|
|
|
123 |
* @param array $options Aws\S3\BatchDelete options array.
|
|
|
124 |
*
|
|
|
125 |
* @see Aws\S3\S3Client::listObjects
|
|
|
126 |
* @throws \RuntimeException if no prefix and no regex is given
|
|
|
127 |
*/
|
|
|
128 |
public function deleteMatchingObjects(
|
|
|
129 |
$bucket,
|
|
|
130 |
$prefix = '',
|
|
|
131 |
$regex = '',
|
|
|
132 |
array $options = []
|
|
|
133 |
);
|
|
|
134 |
|
|
|
135 |
/**
|
|
|
136 |
* Deletes objects from Amazon S3 that match the result of a ListObjects
|
|
|
137 |
* operation. For example, this allows you to do things like delete all
|
|
|
138 |
* objects that match a specific key prefix.
|
|
|
139 |
*
|
|
|
140 |
* @param string $bucket Bucket that contains the object keys
|
|
|
141 |
* @param string $prefix Optionally delete only objects under this key prefix
|
|
|
142 |
* @param string $regex Delete only objects that match this regex
|
|
|
143 |
* @param array $options Aws\S3\BatchDelete options array.
|
|
|
144 |
*
|
|
|
145 |
* @see Aws\S3\S3Client::listObjects
|
|
|
146 |
*
|
|
|
147 |
* @return PromiseInterface A promise that is settled when matching
|
|
|
148 |
* objects are deleted.
|
|
|
149 |
*/
|
|
|
150 |
public function deleteMatchingObjectsAsync(
|
|
|
151 |
$bucket,
|
|
|
152 |
$prefix = '',
|
|
|
153 |
$regex = '',
|
|
|
154 |
array $options = []
|
|
|
155 |
);
|
|
|
156 |
|
|
|
157 |
/**
|
|
|
158 |
* Upload a file, stream, or string to a bucket.
|
|
|
159 |
*
|
|
|
160 |
* If the upload size exceeds the specified threshold, the upload will be
|
|
|
161 |
* performed using concurrent multipart uploads.
|
|
|
162 |
*
|
|
|
163 |
* The options array accepts the following options:
|
|
|
164 |
*
|
|
|
165 |
* - before_upload: (callable) Callback to invoke before any upload
|
|
|
166 |
* operations during the upload process. The callback should have a
|
|
|
167 |
* function signature like `function (Aws\Command $command) {...}`.
|
|
|
168 |
* - concurrency: (int, default=int(3)) Maximum number of concurrent
|
|
|
169 |
* `UploadPart` operations allowed during a multipart upload.
|
|
|
170 |
* - mup_threshold: (int, default=int(16777216)) The size, in bytes, allowed
|
|
|
171 |
* before the upload must be sent via a multipart upload. Default: 16 MB.
|
|
|
172 |
* - params: (array, default=array([])) Custom parameters to use with the
|
|
|
173 |
* upload. For single uploads, they must correspond to those used for the
|
|
|
174 |
* `PutObject` operation. For multipart uploads, they correspond to the
|
|
|
175 |
* parameters of the `CreateMultipartUpload` operation.
|
|
|
176 |
* - part_size: (int) Part size to use when doing a multipart upload.
|
|
|
177 |
*
|
|
|
178 |
* @param string $bucket Bucket to upload the object.
|
|
|
179 |
* @param string $key Key of the object.
|
|
|
180 |
* @param mixed $body Object data to upload. Can be a
|
|
|
181 |
* StreamInterface, PHP stream resource, or a
|
|
|
182 |
* string of data to upload.
|
|
|
183 |
* @param string $acl ACL to apply to the object (default: private).
|
|
|
184 |
* @param array $options Options used to configure the upload process.
|
|
|
185 |
*
|
|
|
186 |
* @see Aws\S3\MultipartUploader for more info about multipart uploads.
|
|
|
187 |
* @return ResultInterface Returns the result of the upload.
|
|
|
188 |
*/
|
|
|
189 |
public function upload(
|
|
|
190 |
$bucket,
|
|
|
191 |
$key,
|
|
|
192 |
$body,
|
|
|
193 |
$acl = 'private',
|
|
|
194 |
array $options = []
|
|
|
195 |
);
|
|
|
196 |
|
|
|
197 |
/**
|
|
|
198 |
* Upload a file, stream, or string to a bucket asynchronously.
|
|
|
199 |
*
|
|
|
200 |
* @param string $bucket Bucket to upload the object.
|
|
|
201 |
* @param string $key Key of the object.
|
|
|
202 |
* @param mixed $body Object data to upload. Can be a
|
|
|
203 |
* StreamInterface, PHP stream resource, or a
|
|
|
204 |
* string of data to upload.
|
|
|
205 |
* @param string $acl ACL to apply to the object (default: private).
|
|
|
206 |
* @param array $options Options used to configure the upload process.
|
|
|
207 |
*
|
|
|
208 |
* @see self::upload
|
|
|
209 |
* @return PromiseInterface Returns a promise that will be fulfilled
|
|
|
210 |
* with the result of the upload.
|
|
|
211 |
*/
|
|
|
212 |
public function uploadAsync(
|
|
|
213 |
$bucket,
|
|
|
214 |
$key,
|
|
|
215 |
$body,
|
|
|
216 |
$acl = 'private',
|
|
|
217 |
array $options = []
|
|
|
218 |
);
|
|
|
219 |
|
|
|
220 |
/**
|
|
|
221 |
* Copy an object of any size to a different location.
|
|
|
222 |
*
|
|
|
223 |
* If the upload size exceeds the maximum allowable size for direct S3
|
|
|
224 |
* copying, a multipart copy will be used.
|
|
|
225 |
*
|
|
|
226 |
* The options array accepts the following options:
|
|
|
227 |
*
|
|
|
228 |
* - before_upload: (callable) Callback to invoke before any upload
|
|
|
229 |
* operations during the upload process. The callback should have a
|
|
|
230 |
* function signature like `function (Aws\Command $command) {...}`.
|
|
|
231 |
* - concurrency: (int, default=int(5)) Maximum number of concurrent
|
|
|
232 |
* `UploadPart` operations allowed during a multipart upload.
|
|
|
233 |
* - params: (array, default=array([])) Custom parameters to use with the
|
|
|
234 |
* upload. For single uploads, they must correspond to those used for the
|
|
|
235 |
* `CopyObject` operation. For multipart uploads, they correspond to the
|
|
|
236 |
* parameters of the `CreateMultipartUpload` operation.
|
|
|
237 |
* - part_size: (int) Part size to use when doing a multipart upload.
|
|
|
238 |
*
|
|
|
239 |
* @param string $fromBucket Bucket where the copy source resides.
|
|
|
240 |
* @param string $fromKey Key of the copy source.
|
|
|
241 |
* @param string $destBucket Bucket to which to copy the object.
|
|
|
242 |
* @param string $destKey Key to which to copy the object.
|
|
|
243 |
* @param string $acl ACL to apply to the copy (default: private).
|
|
|
244 |
* @param array $options Options used to configure the upload process.
|
|
|
245 |
*
|
|
|
246 |
* @see Aws\S3\MultipartCopy for more info about multipart uploads.
|
|
|
247 |
* @return ResultInterface Returns the result of the copy.
|
|
|
248 |
*/
|
|
|
249 |
public function copy(
|
|
|
250 |
$fromBucket,
|
|
|
251 |
$fromKey,
|
|
|
252 |
$destBucket,
|
|
|
253 |
$destKey,
|
|
|
254 |
$acl = 'private',
|
|
|
255 |
array $options = []
|
|
|
256 |
);
|
|
|
257 |
|
|
|
258 |
/**
|
|
|
259 |
* Copy an object of any size to a different location asynchronously.
|
|
|
260 |
*
|
|
|
261 |
* @param string $fromBucket Bucket where the copy source resides.
|
|
|
262 |
* @param string $fromKey Key of the copy source.
|
|
|
263 |
* @param string $destBucket Bucket to which to copy the object.
|
|
|
264 |
* @param string $destKey Key to which to copy the object.
|
|
|
265 |
* @param string $acl ACL to apply to the copy (default: private).
|
|
|
266 |
* @param array $options Options used to configure the upload process.
|
|
|
267 |
*
|
|
|
268 |
* @see self::copy for more info about the parameters above.
|
|
|
269 |
* @return PromiseInterface Returns a promise that will be fulfilled
|
|
|
270 |
* with the result of the copy.
|
|
|
271 |
*/
|
|
|
272 |
public function copyAsync(
|
|
|
273 |
$fromBucket,
|
|
|
274 |
$fromKey,
|
|
|
275 |
$destBucket,
|
|
|
276 |
$destKey,
|
|
|
277 |
$acl = 'private',
|
|
|
278 |
array $options = []
|
|
|
279 |
);
|
|
|
280 |
|
|
|
281 |
/**
|
|
|
282 |
* Recursively uploads all files in a given directory to a given bucket.
|
|
|
283 |
*
|
|
|
284 |
* @param string $directory Full path to a directory to upload
|
|
|
285 |
* @param string $bucket Name of the bucket
|
|
|
286 |
* @param string $keyPrefix Virtual directory key prefix to add to each upload
|
|
|
287 |
* @param array $options Options available in Aws\S3\Transfer::__construct
|
|
|
288 |
*
|
|
|
289 |
* @see Aws\S3\Transfer for more options and customization
|
|
|
290 |
*/
|
|
|
291 |
public function uploadDirectory(
|
|
|
292 |
$directory,
|
|
|
293 |
$bucket,
|
|
|
294 |
$keyPrefix = null,
|
|
|
295 |
array $options = []
|
|
|
296 |
);
|
|
|
297 |
|
|
|
298 |
/**
|
|
|
299 |
* Recursively uploads all files in a given directory to a given bucket.
|
|
|
300 |
*
|
|
|
301 |
* @param string $directory Full path to a directory to upload
|
|
|
302 |
* @param string $bucket Name of the bucket
|
|
|
303 |
* @param string $keyPrefix Virtual directory key prefix to add to each upload
|
|
|
304 |
* @param array $options Options available in Aws\S3\Transfer::__construct
|
|
|
305 |
*
|
|
|
306 |
* @see Aws\S3\Transfer for more options and customization
|
|
|
307 |
*
|
|
|
308 |
* @return PromiseInterface A promise that is settled when the upload is
|
|
|
309 |
* complete.
|
|
|
310 |
*/
|
|
|
311 |
public function uploadDirectoryAsync(
|
|
|
312 |
$directory,
|
|
|
313 |
$bucket,
|
|
|
314 |
$keyPrefix = null,
|
|
|
315 |
array $options = []
|
|
|
316 |
);
|
|
|
317 |
|
|
|
318 |
/**
|
|
|
319 |
* Downloads a bucket to the local filesystem
|
|
|
320 |
*
|
|
|
321 |
* @param string $directory Directory to download to
|
|
|
322 |
* @param string $bucket Bucket to download from
|
|
|
323 |
* @param string $keyPrefix Only download objects that use this key prefix
|
|
|
324 |
* @param array $options Options available in Aws\S3\Transfer::__construct
|
|
|
325 |
*/
|
|
|
326 |
public function downloadBucket(
|
|
|
327 |
$directory,
|
|
|
328 |
$bucket,
|
|
|
329 |
$keyPrefix = '',
|
|
|
330 |
array $options = []
|
|
|
331 |
);
|
|
|
332 |
|
|
|
333 |
/**
|
|
|
334 |
* Downloads a bucket to the local filesystem
|
|
|
335 |
*
|
|
|
336 |
* @param string $directory Directory to download to
|
|
|
337 |
* @param string $bucket Bucket to download from
|
|
|
338 |
* @param string $keyPrefix Only download objects that use this key prefix
|
|
|
339 |
* @param array $options Options available in Aws\S3\Transfer::__construct
|
|
|
340 |
*
|
|
|
341 |
* @return PromiseInterface A promise that is settled when the download is
|
|
|
342 |
* complete.
|
|
|
343 |
*/
|
|
|
344 |
public function downloadBucketAsync(
|
|
|
345 |
$directory,
|
|
|
346 |
$bucket,
|
|
|
347 |
$keyPrefix = '',
|
|
|
348 |
array $options = []
|
|
|
349 |
);
|
|
|
350 |
|
|
|
351 |
/**
|
|
|
352 |
* Returns the region in which a given bucket is located.
|
|
|
353 |
*
|
|
|
354 |
* @param string $bucketName
|
|
|
355 |
*
|
|
|
356 |
* @return string
|
|
|
357 |
*/
|
|
|
358 |
public function determineBucketRegion($bucketName);
|
|
|
359 |
|
|
|
360 |
/**
|
|
|
361 |
* Returns a promise fulfilled with the region in which a given bucket is
|
|
|
362 |
* located.
|
|
|
363 |
*
|
|
|
364 |
* @param string $bucketName
|
|
|
365 |
*
|
|
|
366 |
* @return PromiseInterface
|
|
|
367 |
*/
|
|
|
368 |
public function determineBucketRegionAsync($bucketName);
|
|
|
369 |
}
|