在我的本地服务器上读取 CSV 文件时,leaguecsv 效果很好。我已将 CSV 文件移至 S3 进行生产,现在在进行 getHeader() 调用时出现“搜索”错误。
"{message: "stream 不支持搜索", 异常: "League\Csv\Exception",...}"
在得到 seek 错误后,我尝试了在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);
有人看到这个问题吗?