gpt4 book ai didi

php - 获取 "stream does not support seeking"从 S3 读取 CSV

转载 作者:行者123 更新时间:2023-12-04 03:58:25 29 4
gpt4 key购买 nike

使用 LeagueCSV "^9.6"

在我的本地服务器上读取 CSV 文件时,leaguecsv 工作得很好。我已将 CSV 文件移至 S3 进行生产,现在我在调用 getHeader() 时遇到“查找”错误。

"{message: "stream does not support seeking", 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);

有人看到这个问题吗?

最佳答案

我遇到了同样的问题,这是由 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。

关于php - 获取 "stream does not support seeking"从 S3 读取 CSV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63513424/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com