Created
January 4, 2021 12:41
-
-
Save VaguelyOnline/d94b75782a595f82a1b69d9fcfe6f6a6 to your computer and use it in GitHub Desktop.
Illustrates how to retrieve an S3 hosted asset ETag (likely MD5 sum) from a Laravel application.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Retrieves the ETag for the given S3 key. | |
| * | |
| * @param $key The file key. This is the URL of the object relative to the bucket. It can be found through the S3 portal. | |
| * @return string The ETag | |
| * @throws S3Exception | |
| */ | |
| public function getEtag($key) | |
| { | |
| $adapter = Storage::disk('s3')->getAdapter(); | |
| $client = $adapter->getClient(); | |
| $object = $client->headObject([ | |
| 'Bucket' => config('filesystems.disks.s3.bucket'), | |
| 'Key' => $key | |
| ]); | |
| return $object->get('ETag'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment