Serving Images
The Cloud Storage Tools API provides convenience methods that you can use to serve image files conveniently:
-
CloudStorageTools.getImageServingUrl()
-
CloudStorageTools.deleteImageServingUrl()
One advantage of using this method to serve images rather than simply
making the files public
using
CloudStorageTools::getPublicUrl
, is that the image method listed above allows
dynamic manipulation, such as image resizing, which means you don't have to store
different image sizes.
You use
getImageServingUrl
returns a URL that serves an image. If the image will be displayed within an
HTTPS page, set
secure_url
to
True
to avoid mixed-content warnings.
Notice that this URL is publically readable by everyone, but it is not "guessable".
To stop serving the URL, call deleteImageServingUrl .
The following snippet shows how to use this feature, with the image
myfile.png
made available in a resized and cropped format:
require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php';
use google\appengine\api\cloud_storage\CloudStorageTools;
$object_image_file = 'gs://my-bucket/myfile.png'
$object_image_url = CloudStorageTools::getImageServingUrl($object_image_file,
['crop' => true]
['size' => 400]);
header('Location:' .$object_image_url);