PHP App Engine - Unable to Read Images in Cloud Storage

166 views
Skip to first unread message

Noel McKeown

unread,
Mar 26, 2019, 9:12:33 PM3/26/19
to Google App Engine
Hi users,

We are having some issue reading images stored on our bucket storage.
Using a php55 agg engine to serve the web docs.

Below is our environment and some sample code:

php.ini
extension = "fileinfo.so"
extension = "intl.so"
google_app_engine.allow_include_gs_buckets = "gs://safetyfreelancer-209721.appspot.com/"

app.yaml
service: phpmyadmin
runtime: php55
api_version: 1

handlers:

- url: /(.+\.(ico|jpg|png|gif))$
static_files: \1
upload: (.+\.(ico|jpg|png|gif))$
application_readable: true

- url: /(.+\.(htm|html|css|js))$
static_files: \1
upload: (.+\.(htm|html|css|js))$
application_readable: true

- url: /(.+\.php)$
script: \1
login: admin

- url: /.*
script: index.php
login: admin

Test Code:
<?php
use google\appengine\api\cloud_storage\CloudStorageTools;
try {
$photo = CloudStorageTools::getImageServingUrl('gs://safetyfreelancer-209721.appspot.com/uploads/profile_photos/4494316015c95582d11b344.51085825.jpg', ['size' => 100]);
} catch (Exception $e) {
	print_r( $e->getMessage() );
}
?>

<?php if( !empty($photo) ): ?>
	<img src="<?php echo $photo ?>" alt="<?php echo $photo ?>" /
<?php endif ?>

Test URL:
https://safetyfreelancer.com/test-permissions.php

Error on GCP Console:
PHP Fatal error:  Uncaught exception 'google\appengine\api\cloud_storage\CloudStorageException' with message 'Unspecified error with image.' in /base/alloc/tmpfs/dynamic_runtimes/php55_dynamic/fc2f1b4915ea2bca/sdk/google/appengine/api/cloud_storage/CloudStorageTools.php:810
Stack trace:
#0 /base/alloc/tmpfs/dynamic_runtimes/php55_dynamic/fc2f1b4915ea2bca/sdk/google/appengine/api/cloud_storage/CloudStorageTools.php(331): google\appengine\api\cloud_storage\CloudStorageTools::imagesApplicationErrorToException(Object(google\appengine\runtime\ApplicationError))
#1 /base/data/home/apps/g~safetyfreelancer-209721/20190326t123924.417045301748881360/src/SafetyFreel/Controllers/DefaultController.php(42): google\appengine\api\cloud_storage\CloudStorageTools::getImageServingUrl('gs://safetyfree...', Array)
#2 /base/data/home/apps/g~safetyfreelancer-209721/20190326t123924.417045301748881360/public/index.php(480): SafetyFreel\Controllers\DefaultController->serveFile('profile_photos/...')
#3 [internal function]: {closure}('profile_photos/...' in /base/alloc/tmpfs/dynamic_runtimes/php55_dynamic/fc2f1b4915ea2bca/sdk/google/appengine/api/cloud_storage/CloudStorageTools.php on line 810

The storage is public.
Appreciate if someone can assist pinpoint the issue.

Many Thanks,
Noel
 

Noel McKeown

unread,
Apr 2, 2019, 3:01:49 PM4/2/19
to Google App Engine
This was due to 'Bucket Policy Only' been turned on:
Reply all
Reply to author
Forward
0 new messages