0

Following the instructions for these topics: https://github.com/google/google-api-php-client/issues/788 https://developers.google.com/api-client-library/php/guide/media_upload

I tried to fix the problem below and upload files to Google Drive:

Fatal error: Uncaught GuzzleHttp\Exception\RequestException: cURL error 60: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in /secret/public_html/v5/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:187 Stack trace: #0 /secret/public_html/v5/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(150): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array) #1 /secret/public_html/v5/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(103): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory)) #2 /secret/public_html/v5/vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php(43): GuzzleHttp\Handler\CurlFactory::fin in /secret/public_html/v5/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on line 187

Using the APIs in PHP, when the file is less than 5 MB, it does not show the error, however, files larger than this generate the above error. Is the problem the API or the certificate? Even installing it on my linux server the error continues, does anyone know how to fix this problem? Or have you ever faced something like that?

Here is the code I'm using to upload up to 5 MB that is working.

<?php

$client = new Google_Client();
$client->setAuthConfig("client_secret.json");
$client->setIncludeGrantedScopes(true);
$client->setAccessType("offline");
$client->setAccessToken($access_token);

$drive_service = new Google_Service_Drive($client);

$mime_type = mime_content_type($uploadfile);

$file = new Google_Service_Drive_DriveFile();
$result = $drive_service->files->create($file, array(
    "data" => file_get_contents($uploadfile),
    "mimeType" => $mime_type,
    "uploadType" => "media"
)); 

Following is the code I'm using to upload a larger 5 MB that is not working.

<?php

$client = new Google_Client();
$client->setAuthConfig("client_secret.json");
$client->setIncludeGrantedScopes(true);
$client->setAccessType("offline");
$client->setAccessToken($access_token);

$drive_service = new Google_Service_Drive($client);

$mime_type = mime_content_type($uploadfile);

$file = new Google_Service_Drive_DriveFile();
$file->title = $uploadname;
$chunkSizeBytes = 1 * 1024 * 1024;

$client->setDefer(true);
$request = $drive_service->files->create($file); // insert

$media = new Google_Http_MediaFileUpload($client, $request, $mime_type, null, true, $chunkSizeBytes);
$media->setFileSize(filesize($uploadfile));

$status = false;
$handle = fopen($uploadfile, "rb");

while (!$status && !feof($handle)) {
    $chunk = fread($handle, $chunkSizeBytes);
    $status = $media->nextChunk($chunk);
}

$result = false;
if($status != false) {
    $result = $status;
}

fclose($handle);

$client->setDefer(false);
Simon H
  • 2,495
  • 4
  • 30
  • 38
  • I found in this [SO question](http://stackoverflow.com/questions/35638497) that to solve the error that you got is by disabling the SSL certificate. $guzzleClient = new \GuzzleHttp\Client(array( 'curl' => array( CURLOPT_SSL_VERIFYPEER => false, ), )); $client->setHttpClient($guzzleClient); You can also try the other solution in this [thread](https://laracasts.com/discuss/channels/general-discussion/curl-error-60-ssl-certificate-problem-unable-to-get-local-issuer-certificate). – KENdi Feb 16 '17 at 12:56
  • Following your tip, I used this code: $client->setHttpClient(new GuzzleHttp\Client([ "verify" => false ])); above this line: $client = new Google_Client(); Thanks for your help! – Everaldo Lopes Feb 16 '17 at 16:21
  • Do NOT disable the certificate verifictaion. This allows man in the middle attacks. Download a new cacert.pem, and reference it in your php ini as an openssl cert. – Richard Duerr Oct 18 '18 at 15:02

0 Answers0