簡體   English   中英

Laravel Content-Length header 無法與文件響應一起發送

[英]Laravel Content-Length header can't be sent with file response

我實際上是在嘗試使用以下方法發送 Content-Length header 和我的文件響應(用於在客戶端下載狀態欄目的):

return response()->header('Content-Length', $fileSize)->file($this->filesPath.$fileName);

但我收到一個錯誤:

BadMethodCallException: Method Illuminate\Routing\ResponseFactory::header does not exist. in file /www/vendor/laravel/framework/src/Illuminate/Macroable/Traits/Macroable.php on line 113

當響應中有“file()”時,似乎無法識別該方法。

這是我的響應標頭:

我的標題

注意:Apache webserver 基於 Linux 機器運行 Laravel 8 和 Z2FEC392304A57C23AC138DA21。

使用預建的download()方法發送標頭

$filesPath = 'path/to/file'; // change this
$fileName = 'file-name'; // change this
$fileSize = 'size'; // change this

$headers = [
    'Content-Length' => $fileSize
];

return response()->download($filesPath, $fileName, $headers);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM