/**
  * {@inheritdoc}
  */
 public function write($key, $content)
 {
     $this->ensureBucketExists();
     $path = $this->computePath($key);
     $metadata = $this->getMetadata($key);
     $options = array('uploadType' => 'multipart', 'data' => $content);
     /**
      * If the ContentType was not already set in the metadata, then we autodetect
      * it to prevent everything being served up as application/octet-stream.
      */
     if (!isset($metadata['ContentType']) && $this->detectContentType) {
         $finfo = new \finfo(FILEINFO_MIME_TYPE);
         $options['mimeType'] = $finfo->buffer($content);
         unset($metadata['ContentType']);
     } elseif (isset($metadata['ContentType'])) {
         $options['mimeType'] = $metadata['ContentType'];
         unset($metadata['ContentType']);
     }
     $object = new \Google_Service_Storage_StorageObject();
     $object->name = $path;
     if (isset($metadata['ContentDisposition'])) {
         $object->setContentDisposition($metadata['ContentDisposition']);
         unset($metadata['ContentDisposition']);
     }
     if (isset($metadata['CacheControl'])) {
         $object->setCacheControl($metadata['CacheControl']);
         unset($metadata['CacheControl']);
     }
     if (isset($metadata['ContentLanguage'])) {
         $object->setContentLanguage($metadata['ContentLanguage']);
         unset($metadata['ContentLanguage']);
     }
     if (isset($metadata['ContentEncoding'])) {
         $object->setContentEncoding($metadata['ContentEncoding']);
         unset($metadata['ContentEncoding']);
     }
     $object->setMetadata($metadata);
     try {
         $object = $this->service->objects->insert($this->bucket, $object, $options);
         if ($this->options['acl'] == 'public') {
             $acl = new \Google_Service_Storage_ObjectAccessControl();
             $acl->setEntity("allUsers");
             $acl->setRole("READER");
             $this->service->objectAccessControls->insert($this->bucket, $path, $acl);
         }
         return $object->getSize();
     } catch (\Google_Service_Exception $e) {
         return false;
     }
 }
 private function upload_to_gcs($url, $content, $mime)
 {
     $obj = new Google_Service_Storage_StorageObject();
     $obj->setName($url);
     $this->gcs_storage->objects->insert($this->gcs_bucket, $obj, ['data' => $content, 'uploadType' => 'media', 'mimeType' => $mime]);
     $acl = new Google_Service_Storage_ObjectAccessControl();
     $acl->setEntity('allUsers');
     $acl->setRole('READER');
     $this->gcs_storage->objectAccessControls->insert($this->gcs_bucket, $url, $acl);
 }