-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcloud.php
32 lines (30 loc) · 1 KB
/
cloud.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
use Google\Cloud\Storage\StorageClient;
// Create Http context details
/**$contextData = array (
'body' => json_encode('{"requests": [{"image": {"content": "BASE64-ENCODED-IMAGE-HERE" }, "features": [ {"maxResults": 10,"type": "OBJECT_LOCALIZATION"}]}]}'),
'method' => 'POST',
'header' => "Connection: close\r\n".
"Content-Length: ".strlen($query)."\r\n",
'content'=> $query );
**/
/**
* Upload a file.
*
* @param string $bucketName the name of your Google Cloud bucket.
* @param string $objectName the name of the object.
* @param string $source the path to the file to upload.
*
* @return Psr\Http\Message\StreamInterface
*/
function upload_object($bucketName, $objectName, $source)
{
$storage = new StorageClient();
$file = fopen($source, 'r');
$bucket = $storage->bucket($bucketName);
$object = $bucket->upload($file, [
'name' => $objectName
]);
printf('Uploaded %s to gs://%s/%s' . PHP_EOL, basename($source), $bucketName, $objectName);
}
?>