3

Using LeagueCSV "^9.6"

when reading a CSV file on my local server leaguecsv worked great. I've moved the CSV file to S3 for production and now i'm getting a "seek" error when making the getHeader() call.

"{message: "stream does not support seeking", exception: "League\Csv\Exception",…}"

after getting the seek error I tried the following change that I saw on Github as follows with no help:

        $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
            )
        ));

I also changed from createFromPath (worked when file was on local server) to createFromStream for S3

        //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);

does anyone see the issue?

scottsuhy
  • 315
  • 4
  • 13

1 Answers1

1

I've got the same issue which is caused by a BC in flysystem-aws-s3-v3 v1.0.28 https://github.com/thephpleague/flysystem-aws-s3-v3/commit/c73ebc5b78076e971ec64fdab8a5a956d118b160

Please refer to https://github.com/thephpleague/flysystem-aws-s3-v3/issues/218. I've currently fixed the version to v1.0.27.

Alexcode
  • 1,598
  • 7
  • 15