Type to search...

Image deletion by tags


There are cases when users need to delete a large number of images. Deleting one by one is an expensive and inefficient way. Using bulk requests for deleting is a better solution, but still complicated, need to care about rate limitation, etc. We recommend using our deleteByTag solution.

The deleteByTag function works with jobs, which are Shardimage background processes for resource-intensive tasks. Important to note, this solution requires a well-chosen image tag, to delete images efficiently. For choosing the best tags, please check our guide about image tags here »


Let’s say, we have a social media site, and we need to manage images of a deleted user, in the most strict case, we need to remove all of it. If we used the user ID for the image tag, we can delete all of it, with a single request.

use shardimage\shardimagephp\auth\Client;
$client = new Client([
    'apiKey' => '<apiKey>',
    'apiSecret' => '<apiSecret>',
    'imageSecret' => '<imageSecret>',
    'cloudId' => '<cloudId>',
$params = [
    'tag' => '<imageTag>',     // tag which came from the user ID
    'cloudId' => '<cloudId>',  // where we store the user images
$response = $client->getImageService()->deleteByTag($params);

For checking the status of the job, let’s have an example with variables from the previous example:

use shardimage\shardimagephp\models\job\Job;
if ($response instanceof Job) {
    $job = $client->getJobService()->view($response->id);
    echo $job->stasus;
} else {
    // Handle error
Table of contents