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?