将Google云存储与Google应用引擎相关联

时间:2014-04-11 07:51:11

标签: codeigniter google-app-engine google-cloud-storage

如何将Google App Engine中的我的Codeigniter项目与Google云端存储相关联?

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您可以使用PHP客户端库[1]。这里有一个将文件上传到存储桶的示例:

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