如何使用symfony/gauferette/VichUploaderBundle将文件上传到Google Cloud Storage [英] how to upload files to Google Cloud Storage with symfony / gauferette / VichUploaderBundle

查看:130
本文介绍了如何使用symfony/gauferette/VichUploaderBundle将文件上传到Google Cloud Storage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好

我正在通过VichUploaderBundle在本地上载我的文件.每件事都很完美.

I am uploading my files locally through VichUploaderBundle. Every thing works perfectly.

现在,我不再希望将文件存储在本地:我想将它们存储在 Google Cloud Storage 上.我发现 KnpGaufretteBundle 可用于在云中存储文件.

Now I want no more store my files locally: I want to store them on Google Cloud Storage. I found that KnpGaufretteBundle could be used for storing files in the cloud.

因此,关于如何配置 Gaufrette (PHP软件包) KnpGaufretteBundle ( symfony捆绑包)用于在google-cloud-storage上存储/上传/读取文件?

So, is there any example or a example's link on how to configure Gaufrette (the php package) or KnpGaufretteBundle (the symfony bundle) for storing/uploading/reading files on google-cloud-storage?

我唯一发现的是链接这是GoogleCloudStorage的适配器类.

The only thing I found is that link which is an adapter class for GoogleCloudStorage.

我找到了与此问题有关的另一个链接,但它提出了一个在amazon-s3上存储文件的示例:

I found another link regarding this issue but it proposes an example for storing files on amazon-s3: upload-files-to-amazon-s3-with-symfony2-and-gaufrette

感谢您的帮助...

推荐答案

可以使用KnpGaufretteBundle来做到这一点.您只需要创建一个工厂即可创建经过完全认证的Google客户端,并随该客户端一起返回Google服务存储.像这样的东西:

Is possible to use KnpGaufretteBundle to do that. You only need to create a factory that creates a Google Client fully authenticated and return the Google Service Storage with that Client. Something like that:

/**
 * @return \Google_Service_Storage
 */
public function createService($privateKeyPath, $password, $googleAccountName)
{
    $client = new \Google_Client();
    $scopes = array(
        'https://www.googleapis.com/auth/devstorage.read_write'
    );

    $privateKey = file_get_contents($privateKeyPath);

    $credential = new \Google_Auth_AssertionCredentials(
        $googleAccountName, $scopes, $privateKey, $password
    );

    $client->setAssertionCredentials($credential);

    return new \Google_Service_Storage($client);
}

您还需要配置KnpGaufretteBundle,以查看以下内容: KnpGaufretteBundle-GoogleCloudStorage

You also need to configure the KnpGaufretteBundle, for this look at: KnpGaufretteBundle-GoogleCloudStorage

在GitHub上有一篇帖子解释了工厂问题: 发布

Here there's a post in GitHub where explains the factory issue: post

这篇关于如何使用symfony/gauferette/VichUploaderBundle将文件上传到Google Cloud Storage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆