Image is not properly uploading to Google Cloud storage using GAE php

108 views
Skip to first unread message

tejashree mahadik

unread,
Dec 26, 2016, 9:55:00 AM12/26/16
to Google App Engine
I am trying to upload image from Google App Engine using PHP. Image is getting uploaded to proper cloud storage bucket path, but it is not accessible as it contains error. When I am uploading 800kb size image, it is showing 12 byte to cloud storage. I've also tried to upload 1kb size file, even though it is showing 12 byte size. I am not getting the exact issue. Here is my code for uploading image to google cloud storage:

Here is my code :

$file_name = $_FILES['filetoUpload']['name'];
            $temp_name = $_FILES['filetoUpload']['tmp_name'];
            $type = $_FILES['filetoUpload']['type'];
            $options = array('gs' => array('entity' => 'allUsers', 'role' => 'READER', 'acl' => 'public-read', 'Content-Type' => $type, 'contentEncoding' => 'ANSI'));
            $context = stream_context_create($options);
            $publicFileText = date('ymdhis');
            $fileName = "gs://<bucket-name>/" . $file_name;
            file_put_contents($fileName, $publicFileText, 0, $context);
            $publicUrl = CloudStorageTools::getPublicUrl($fileName, TRUE);

George (Cloud Platform Support)

unread,
Dec 28, 2016, 12:54:33 PM12/28/16
to Google App Engine

Hi Tejashree,


In the statement: “$options = array('gs' => array('entity' => 'allUsers', 'role' => 'READER', 'acl' => 'public-read', 'Content-Type' => $type, 'contentEncoding' => 'ANSI'));”

The ANSI value does not seem right. Content-Type can be “Any valid MIME type”, for instance “text/plain”. You describe your saved content as an image, not text. You may consider looking closer to the way this metadata is set. If somehow only text gets saved, and not the intended image, your file size would appear small, just as you describe it here.


The statement: “ $publicFileText = date('ymdhis');” seems to indicate a text file as well, storing a date.


What are the steps you have undertaken to finally store the image with the help of your PHP program? Any relevant detail might help, and information from logs, and the like.


Reply all
Reply to author
Forward
0 new messages