I'm upload multiple images inside Picture
(like folder) under Google Cloud Storage bucket.
Eg. Picture/a.jpg, Picture/b.jpg, Pictuer/c.jpg, .....
Now, I want to directly show those multiple images from Cloud Storage into my cakephp 2.x web application as a list.
According to Google Cloud Storage documentation, to access each object inside bucket, Signed URLs must be generated. So, I created signed URLs for each object based on my selecting data from database. Following is my sample code.
<?php
# Imports the Google Cloud client library
use Google\Cloud\Storage\StorageClient;
use Google\Cloud\Core\Exception\GoogleException;
function index() {
//$rsl = 'select data from database';
for($i=0; $i<$count; $i++) {
# create url to access image from google cloud storage
$file_path = $rsl[$i]['pic']['file_path'];
if(!empty($file_path)) {
$rsl[$i]['pic']['real_path'] = $this->get_object_v4_signed_url($file_path);
} else {
$rsl[$i]['pic']['real_path'] = '';
}
}
}
/**
* Generate a v4 signed URL for downloading an object.
*
* @param string $bucketName the name of your Google Cloud bucket.
* @param string $objectName the name of your Google Cloud object.
*
* @return void
*/
function get_object_v4_signed_url($objectName) {
$cloud = parent::connect_to_google_cloud_storage();
$storage = $cloud[0];
$bucketName = $cloud[1];
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
if($object->exists()) {
$url = $object->signedUrl(
# This URL is valid for 1 minutes
new \DateTime('1 min'),
[
'version' => 'v4'
]
);
} else {
$url = '';
}
return $url;
}
?>
The problem is, it takes too long to generate because each file is generated to v4 signed URL. When I read Google Cloud Storage documentation, I didn't see to generate v4 signed URL of multiple objects at once(may be I'm wrong). So, is there anyway to speed it up this generating process?