I have an app that lets users upload an image, and I want other users to be able to see that image.
I am using the CloudStorageTools::createUploadUrl method to allows users to upload via POST. I am then taking the uploaded file and using move_uploaded_file to store it on Google Cloud Storage.
Then, I am using CloudStorageTools::getPublicUrl to get the URL for the file. It returns the correct URL, but the file is not publicly accessible so I get a XML error response "AccessDenied".
I know this is because the file isn't shared publicly, but I'm not sure how to make it public after it gets upload.
I tried passing in a "acl=public-read" option to createUploadUrl, but it returned an error of unknown option.
I see an example of how todo this on this page: https://developers.google.com/appengine/docs/php/googlestorage/public_access however, my workflow requires me to allow normal POST uploads using the createUploadUrl method as shown here: https://developers.google.com/appengine/docs/php/googlestorage/user_upload
How do I make user uploaded files automatically publicly accessible?
As of September 23 2014, I managed to upload files to Google Storage Cloud via appEngine and set the
acl
topublic-read
(everyone) like this:form.php:
upload_handler.php:
To be able to accept big files, I've also created a custom
php.ini
on the base directory of my app:php.ini:
app.yaml, sets all images files as static and
.php's
as runnable, it looks like this:Hope it helps anyone else ;)
Got this to work using file_put_contents with a stream.
Old code
New code, sets permissions and mime type
Go me!
None of the options listed here seem to work anymore.
The only way I've been able to get public access for files it to create a bucket with public access and use that for uploaded files.
the option max_file_uploads can't be 0.
max_file_uploads = 10 (or whatever you want)