【问题标题】:Getting "stream does not support seeking" reading CSV from S3从 S3 获取“流不支持搜索”读取 CSV
【发布时间】:2020-12-10 06:47:50
【问题描述】:

使用LeagueCSV "^9.6"

在我的本地服务器上读取 CSV 文件时,leaguecsv 效果很好。我已将 CSV 文件移至 S3 进行生产,现在在调用 getHeader() 时出现“seek”错误。

"{message: "stream does not support seek", exception: "League\Csv\Exception",...}"

在出现查找错误后,我尝试了在Github 上看到的以下更改,但没有任何帮助:

        $s3Client = \Aws\S3\S3Client::factory(array(
            'version' => 'latest',
            'region' => env('AWS_DEFAULT_REGION'),
            'credentials' => array(
                'key'    => env('AWS_ACCESS_KEY_ID'),
                'secret' => env('AWS_SECRET_ACCESS_KEY'),
            ),
        ));
        
        $s3Client->registerStreamWrapper();

        $context = stream_context_create(array(
            's3' => array(
                'seekable' => true
            )
        ));

我也从 createFromPath(文件在本地服务器上时工作)更改为 S3 的 createFromStream

        //load the CSV document from a file path
        //$csv = Reader::createFromPath($FileNameOnEC2, 'r');  <<--this worked fine when the file was on the local server
        $stream = fopen($FileNameOnS3, 'r', false, $context);
        $csv = \League\Csv\Reader::createFromStream($stream);

        $csv->setHeaderOffset(0);

        $header = $csv->getHeader(); //returns the CSV header record // <<-- calling this causes the error 

        $records = $csv->getRecords(); 
        $content = $csv->getContent();
        
        $stmt = (new Statement());

        $records = $stmt->process($csv);

有人看到这个问题吗?

【问题讨论】:

    标签: php amazon-s3 thephpleague


    【解决方案1】:

    我遇到了同样的问题,这是由 flysystem-aws-s3-v3 v1.0.28 https://github.com/thephpleague/flysystem-aws-s3-v3/commit/c73ebc5b78076e971ec64fdab8a5a956d118b160 中的 BC 引起的

    请参考https://github.com/thephpleague/flysystem-aws-s3-v3/issues/218。 我目前已将版本修复为 v1.0.27。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-11
      • 1970-01-01
      • 2015-05-29
      • 1970-01-01
      • 2016-05-08
      • 2020-03-13
      相关资源
      最近更新 更多