我目前正在為一個專案制定一條路線,我需要從 S3 獲取特定檔案,讀取其內容,然后作為二進制檔案回傳。我不能只使用 S3 檔案 url,因為它是私有的并且是有意的(我們只是不想打開存盤桶檔案)。
但問題是,我想在新頁面中流式傳輸它,而無需下載檔案。
服務:
$file = $this->s3Provider->getFileContents(false); // gets the file binary
return $file;
控制器:
return response()->streamDownload(function() use($file) {
echo $file; // streams data to download it, but I want just to show the file...
}, $filename);
uj5u.com熱心網友回復:
我以為你在使用 Laravel,如果是這樣,那么你可以像這樣回傳你的影像:
return response($file, $filename, [
'Content-Type' => 'image/png',
'Content-Length' => filesize($file)
]);
我用來回傳影像的另一種方法是:
return response()->file($path, array('Content-Type'=>'image/jpg'));
Content-Type 應該是您的影像型別(JPG、PNG 等)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/378534.html
上一篇:執行移動操作的S3策略
