public function deleteImageVariations($user, $imageIdentifier, $width = null)
{
// If width is specified, delete only the specific image
if ($width !== null) {
$this->getClient()->deleteObject(['Bucket' => $this->params['bucket'], 'Key' => $this->getImagePath($user, $imageIdentifier, $width)]);
return true;
}
// If width is not specified, delete every variation. Ask S3 to list all files in the
// directory.
$variationsPath = $this->getImagePath($user, $imageIdentifier);
$varations = $this->getClient()->getIterator('ListObjects', ['Bucket' => $this->params['bucket'], 'Prefix' => $variationsPath]);
// Note: could also use AWS's deleteMatchingObjects instead of deleting items one by one
foreach ($varations as $variation) {
$this->getClient()->deleteObject(['Bucket' => $this->params['bucket'], 'Key' => $variation['Key']]);
}
return true;
}