Type to search...

URL length limitation

When transforming an image, you need to consider the fact that the header requests of the URL and the HTTP together cannot exceed 16 Kbytes. Official SDK-s allow 14 Kbytes when generating the URL.

If you are using your own CDN service, please note that it is possible that in those cases, the allowed URL size may be even smaller. E.g.: with Fastly it’s 8 Kbytes.

Also, please note that browsers may also apply limitations to the length of the URL when serving the images.

Additional useful information on this subject: https://stackoverflow.com/a/417184/6856708

Example code

use shardimage\shardimagephp\auth\Client;
use shardimage\shardimagephp\factories\Text;
use shardimage\shardimagephp\factories\Transformation;
 
$client = new Client([
    'apiKey' => '<apiKey>',
    'apiSecret' => '<apiSecret>',
    'imageSecret' => '<imageSecret>',
    'cloudId' => '<cloudId>',
]);
// $client->setUrlSizeLimit(15); // throws an exception because 14 KiB is the limit
// generating an URL:
$publicId = 'example_image';
$transformation = new Transformation();
for ($i = 0; $i < 100; $i++) {
    $text = (Text::create('Example URL length'))->googleFonts('Montserrat')->base64()->weight(Text::WEIGHT_BOLD)->size(50);
    $transformation->group()->gTopLeft()->color('red')->textOverlay($text);
}
// URL generation will succeed
$url = $client->getUrlService()->create([
    'publicId' => $publicId,
        ], [
    'security' => 'basic',
    'transformation' => $transformation,
]);
$client->setUrlSizeLimit(5); // setting the limit to 5 KiB
// URL generation will throw an exception because the URL size is bigger than 5 KiB
$url = $client->getUrlService()->create([
    'publicId' => $publicId,
        ], [
    'security' => 'basic',
    'transformation' => $transformation,
]);
Table of contents