1
votes

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:

$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);
1

1 Answers

1
votes

You are not uploading the image file. You are just uploading $publicFileText, which is a string.