Inserting an Image in google cloud storage using php api -


i trying setup storage in google cloud platform. kind of confused on do.

i using following code.

require_once("vendor/autoload.php");  use google\cloud\storage\storageclient;  use google\cloud\storage\storageobject;  use google\cloud\storage;  $projectid = 'your_project_id';  $storage = new storageclient([      'projectid' => 'xx',     'key'=> 'yy' ]);  $file_name = "imagename";  $obj = new storageobject();  $obj->setname($file_name);     $storage->objects->insert(         "kmapsimage",         $obj,         ['name' => $file_name, 'data' => file_get_contents("https://kmapst.blob.core.windows.net/images/kmap581b939a7a28c.jpeg"),'mimetype' => 'image/jpeg'] ); 

on executing function following error.

argument 1 passed google\cloud\storage\storageobject::__construct() must implement interface google\cloud\storage\connection\connectioninterface, none given, called in /var/www/html/test_imageupload.php on line 35 , defined in /var/www/html/vendor/google/cloud/src/storage/storageobject.php on line 71 

i want upload images google storage.

the docs show simpler way

given relevant code:

$storage = new storageclient([     'projectid' => 'xx',     'key'=> 'yy' ]); 

// using upload method seems bit more straightforward

$bucket = $storage->bucket('bucket-name'); $file = fopen('path/to/file', 'r'); $object = $bucket->upload($file, ['name' => 'filename']); 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -