【问题标题】:laravel view pdf file from s3 in new tablaravel 在新标签页中查看来自 s3 的 pdf 文件
【发布时间】:2021-08-02 03:59:40
【问题描述】:

如何在新标签页中从 s3 打开 pdf 文件?

以下代码下载文件..但我想在浏览器中查看它

在控制器中存储方法

public function store(Request $request)
  { 
    $validated = $request->validate([
        'leg_number'    => 'required',
        'leg_year'      => 'required',
        'leg_title'     => 'required',
        'leg_type_id'     => 'required',
        'leg_published' => 'required',
        'file'          => 'required',
      ]);

      $name = $request->leg_number . '_' . $request->leg_year . '.pdf';
      $path = 'documents/' . $name;
      Storage::disk('s3')->put($path, $request->file, 'public');
      $validated['leg_path'] = $name;
      $document = Legislation::create($validated);
  }

在控制器中显示方法


public function showLegislation(Legislation $legislation)
  {

   $content = Storage::disk('s3')->get('documents/' . $legislation->leg_path);

    $header = [
      'Content-Type' => 'application/pdf',
      'Content-Disposition' => 'inline; filename="' . $legislation->leg_path . '"'
    ];

    return Response::make($content, 200, $header);
  }

路线

Route::get('legislation/show/{legislation}', [LegislationController::class, 'showLegislation'])->name('legislation.show');

刀片


<a href="{{ route('admin.legislation.show', $leg->id) }}" target="_blank"></a>

【问题讨论】:

  • 您希望 pdf 显示在浏览器中而不是下载它?
  • 是的..这正是我想要的
  • 您是否尝试将Content-Disposition 标头设置为inline
  • 我试过..但同样的事情...正在下载
  • 我发现问题与 chrome 浏览器有关......因为 Firefox 按我的意愿在新选项卡中打开文件!

标签: amazon-s3 laravel-8


【解决方案1】:

最后......它是internet dwonlaod manager 捕获链接并下载文件..如果我禁用它..一切正常

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-26
    • 1970-01-01
    • 2023-01-21
    • 1970-01-01
    • 1970-01-01
    • 2016-10-21
    • 2016-02-02
    • 1970-01-01
    相关资源
    最近更新 更多