【问题标题】:GAE php application unable to find "gs" wrapperGAE php 应用程序无法找到“gs”包装器
【发布时间】:2018-04-17 15:09:04
【问题描述】:

我正在编写一个简单的 php 应用程序来测试对 Cloud Storage 存储桶的读/写准备工作

存储桶已定义并且在通过控制台 Web 界面访问时可以完美运行

但是虽然我在文档之后定义了 composer.json、php.ini 和 app.yaml,但在运行时我收到以下消息:

警告:file_put_contents(): 无法找到包装器“gs” - 您在配置 PHP 时是否忘记启用它?

代码是

<?php

require_once '../vendor/autoload.php';

$destination = "gs://contest17014.appspot.com/ripetiOra_82833hd93hd9dh.mp3";
file_put_contents($destination, $output); 

?>

其中 $output 是本地生成的 mp3 文件(为清楚起见不包括在内)

我阅读了应该自动包含包装器的文档,但这被写入标准 env 文档,而灵活的 env 文档中没有提及。 我应该自己定义这个包装器吗?

【问题讨论】:

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


    【解决方案1】:

    我相信您的file_put_content 参数已经切换,它们应该是:

    <?php
    
    require_once '../vendor/autoload.php';
    
    $destination = "gs://contest17014.appspot.com/ripetiOra_82833hd93hd9dh.mp3";
    file_put_contents($destination, $output); 
    ?>
    

    【讨论】:

      【解决方案2】:

      gs:// 仅在 standard 环境中支持。对于flex 或其他环境,您必须使用StorageClient

      通过composer 包含google/cloud-datastore 库。

      示例:

      $ composer require google/cloud-storage

      <?php
      require 'vendor/autoload.php';
      
      use Google\Cloud\Storage\StorageClient;
      
      $storage = new StorageClient([
          'projectId' => 'my_project'
      ]);
      
      $bucket = $storage->bucket('my_bucket');
      
      // Upload a file to the bucket.
      $bucket->upload(
          fopen('/data/file.txt', 'r')
      );
      
      // Using Predefined ACLs to manage object permissions, you may
      // upload a file and give read access to anyone with the URL.
      $bucket->upload(
          fopen('/data/file.txt', 'r'),
          [
              'predefinedAcl' => 'publicRead'
          ]
      );
      
      // Download and store an object from the bucket locally.
      $object = $bucket->object('file_backup.txt');
      $object->downloadToFile('/data/file_backup.txt');
      

      【讨论】:

        【解决方案3】:

        对于php72standard env

        use Google\Cloud\Storage\StorageClient; 
        function register_stream_wrapper($projectId) {   
            $client = new StorageClient(['projectId' => $projectId]);
            $client->registerStreamWrapper();
        }
        register_stream_wrapper("projectId");
        

        感谢James Crowley

        【讨论】:

          猜你喜欢
          • 2019-10-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-11-19
          • 2013-09-09
          • 2021-08-11
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多