S3ClientInterface.php 14 KB

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