Skip to content

Instantly share code, notes, and snippets.

@VaguelyOnline
Created January 4, 2021 12:41
Show Gist options
  • Save VaguelyOnline/d94b75782a595f82a1b69d9fcfe6f6a6 to your computer and use it in GitHub Desktop.
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.
/**
* 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