php - Google app-engine - Uploaded files not public on google cloud storage -
php - Google app-engine - Uploaded files not public on google cloud storage -
i have app lets users upload image, , want other users able see image.
i using cloudstoragetools::createuploadurl method allows users upload via post. taking uploaded file , using move_uploaded_file store on google cloud storage.
then, using cloudstoragetools::getpublicurl url file. returns right url, file not publicly accessible xml error response "accessdenied".
i know because file isn't shared publicly, i'm not sure how create public after gets upload.
i tried passing in "acl=public-read" alternative createuploadurl, returned error of unknown option.
i see illustration of how todo on page: https://developers.google.com/appengine/docs/php/googlestorage/public_access however, workflow requires me allow normal post uploads using createuploadurl method shown here: https://developers.google.com/appengine/docs/php/googlestorage/user_upload
how create user uploaded files automatically publicly accessible?
got work using file_put_contents stream.
$file = $_files['myfile'] $storeat = 'gs://bucketname/filename.jpg
old code
$saved = move_uploaded_file($file['tmp_name'],$storeat);
new code, sets permissions , mime type
$options = array('gs'=>array('acl'=>'public-read','content-type' => $file['type'])); $ctx = stream_context_create($options); $saved = file_put_contents($storeat, file_get_contents($file['tmp_name']), 0, $ctx);
go me!
php google-app-engine google-cloud-storage
Comments
Post a Comment