我终于在我的项目中测试了外部文件存储系统,当我试图分析其中一些文件时,我遇到了一个奇怪的错误。
我试图实现的目标是:获取特定s3目录中所有文件的列表(已完成),并使用php包通过它们的ID3标记来分析它们:
https://packagist.org/packages/james-heinrich/getid3
$files = Storage::disk('s3')->files('going/down/to/the/bargin/basement/because/the/bargin/basement/is/cool'); //Get Files
$file = Storage::disk('s3')->url($files[0]); // First things first... let's grab the first one.
$getid3 = new getID3; // NEW OBJECT!
return $getid3->analyze($file); // analyze the file!然而,当我把它扔进修补器里时,它会对我发出回响:
"GETID3_VERSION" => "1.9.14-201703261440",
"error" => [
"Could not open "https://a.us-east-2.amazonaws.com/library/pending/admin/01%20-%20Cathedrals.mp3" (!is_readable; !is_file; !file_exists)",
],哪一个似乎表明文件不可读?这是我第一次使用AWS S3,所以可能有些东西我没有正确配置。
发布于 2017-10-20 17:33:46
问题是您要将URL传递给analyze方法。这里提到的是这里。
要分析HTTP或FTP上的远程文件,您需要先在本地复制该文件,然后再运行getID3()
理想情况下,您将从您的URL本地保存文件,然后传递给getID3->analyze()
// save your file from URL ($file)
// I assume $filePath is the local path to the file
$getID3 = new getID3;
return $getID3->analyze($filePath); // $filePath should be local file path and not a remote URL在本地保存s3文件
$contents = $exists = Storage::disk('s3')->get('file.jpg');
$tmpfname = tempnam("/tmp", "FOO");
file_put_contents($tmpfname, $contents);
$getID3 = new getID3;
// now use $tmpfname for getID3
$getID3->analyze($tmpfname);
// you can delete temporary file when done发布于 2017-10-20 17:28:04
您需要将文件从S3提取到本地存储,然后将文件的本地路径传递给getID3的analyze方法。
# $file[0] is path to file in bucket.
$firstFilePath = $file[0];
Storage::put(
storage_path($firstFilePath),
Storage::get($firstFilePath)
);
$getid3->analyze(storage_path($firstFilePath));https://stackoverflow.com/questions/46854142
复制相似问题