从S3获取“流不支持搜索”读取CSV

问题描述

使用LeagueCSV "^9.6"

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

” {消息:“信息流不支持搜索”,例外:“ 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);

有人看到这个问题吗?

解决方法

我遇到了由flys​​ystem-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。