2017-10-20 97 views
0

我終於開始在我的項目中測試外部文件存儲系統,並在嘗試分析其中一些文件時遇到奇怪的錯誤。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,因此可能有些事情我沒有正確配置。

回答

1

問題是您正在將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 
1

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文檔,我有點困惑。它看起來像推薦的用途是上傳? –