Laravel getID3无法从S3中拉取文件

Laravel getID3无法从S3中拉取文件

问题描述:

我终于开始在我的项目中测试外部文件存储系统,并在尝试分析其中一些文件时遇到奇怪的错误。Laravel getID3无法从S3中拉取文件

我想要实现:抓住所有的文件列表中的某个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:/bangerz-army-qa.s3.us-east-2.amazonaws.com/library/pending/admin/01%20-%20Cathedrals.mp3" (!is_readable; !is_file; !file_exists)", 
], 

这似乎表明该文件无法读取?这是我第一次使用AWS S3,因此可能有些事情我没有正确配置。

问题是您正在将URL传递给analyze方法。这提到了here

分析远程文件HTTP或FTP,您需要将文件在本地先运行getID3之前复制()

理想情况下,你会从你的网址文件保存到本地,然后传递给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 

GetId3 doesn't have support for remote files

您需要将文件从S3拉到本地存储,然后将文件的本地路径传递到getID3analyze方法。

# $file[0] is path to file in bucket. 
$firstFilePath = $file[0]; 

Storage::put(
    storage_path($firstFilePath), 
    Storage::get($firstFilePath) 
); 

$getid3->analyze(storage_path($firstFilePath)); 
+0

啊哈!我有一种感觉可能是它的一部分。现在文件存储文档看起来有点亮,那么如何将文件从磁盘移动到网站上的临时文件夹? –

+0

现在我得到一个hashName()字符串错误?看着laravel文档,我有点困惑。它看起来像推荐的用途是上传? –