简体   繁体   English

将Google云存储与Google App引擎连接

[英]Connect Google cloud storage with Google app engine

How can I connect My Codeigniter Project in Google App Engine with Google Cloud Storage? 如何将Google App Engine中的我的Codeigniter项目与Google Cloud Storage连接起来?

Any ideas? 有任何想法吗?

You can use the PHP Client Library [1]. 您可以使用PHP客户端库[1]。 Here you hace an example to upload a file to a bucket: 在这里,您有一个将文件上传到存储桶的示例:

use Google\Cloud\Storage\StorageClient;

/**
 * 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);
}

[1] https://cloud.google.com/storage/docs/reference/libraries#client-libraries-install-php [1] https://cloud.google.com/storage/docs/reference/libraries#client-libraries-install-php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM