duanchen7036 2019-08-19 04:40
浏览 238

如何准备一个非常大的文件供用户使用Laravel下载?

Here is what I want to do :

  1. User purchases a big file (1GB)
  2. Download link is created with laravel's Signed URLs (link is valid for one day)
  3. User can download the file without seeing the actual URL

Here is the working code:

if (!request()->hasValidSignature()) {
            abort(404);
        }

$file = ProductFile::findOrFail($id);
return response()->download($file->path);

But the problem is it takes up all the server's RAM. Even my website does not load while downloading.

I searched around and I think there are two ways:

one: chunking the file and using response:stream(). I tried this, it's working but the download is not Resumable. How to make it resumable? I know I should use Accept-Ranges header But How to do it in laravel?

two: putting the file in a static download host and hide the actual URL. How?

Thank you very much

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算
    • ¥15 java如何提取出pdf里的文字?