I can successfully upload small size files to Google Cloud Storage using Google PHP API CLIENT, But cant upload a 300MB file. Return with memory error. Here is my code.
$storage = new Google_Service_Storage($client);
$file_name = "filenameo.zip";
$obj = new Google_Service_Storage_StorageObject();
$obj->setName($file_name);
$resp = $storage->objects->insert(
"bucketname",
$obj,
array('name' => $file_name, 'data' => file_get_contents("300mb-file.zip"), 'uploadType' => 'media')
);
i tried to change the UploadType to resumable .. but no luck. Please help.
Update: Used the Http as Brandon Yarbrough answer
receiving error (Fatal error: Uncaught exception 'Google_IO_Exception')
$storage = new Google_Service_Storage($client);
$obj = new Google_Service_Storage_StorageObject();
$obj->setName("filenameo.zip");
$obj->setBucket("bucketname");
$filen = "300mb-file.zip";
$mimetype = mime_content_type($filen);
$chunkSizeBytes = 1 * 1024 * 1024;
$client->setDefer(true);
$status = false;
$filetoupload = array('name' => $file_name, 'data' => $filen, 'uploadType' => 'media');
$request = $storage->objects->insert("bucketname",$obj,$filetoupload);
$media = new Google_Http_MediaFileUpload($client, $request, $mimetype, $chunkSizeBytes);
$handle = fopen($filen, "rb");
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
$result = false;
if($status != false) {
$result = $status;
}
fclose($handle);
// Reset to the client to execute requests immediately in the future.
$client->setDefer(false);
Got it working with the below code.