2

我将文件上传到数据库并使用“php artisan storage:link”创建了存储链接,一切正常,但是当我想下载文件时,我遇到了这个错误在此处输入图像描述

这是我的代码

路线

Route::get('/download/{id}', [\App\Http\Controllers\SubjectController::class, 'downloadFile'])->name('subject.download');

Vue.js

<inertia-link :href="'/download/'+slide.id" class="rounded-lg bg-gray-200 px-4 py-1">
      <Icon name="download"></Icon>
</inertia-link>

控制器

    public function downloadFile($id) {
        $file = Upload::find($id);
        $subjectCode = $file->subject()->get()->map->only('name','code')->first()['code'];
        $subjectName = $file->subject()->get()->map->only('name','code')->first()['name'];
        return response()->download(storage_path('app/public/documents/'.Str::upper($subjectCode.'_'.$subjectName).'/'.$file->file), 'public');
    }
4

1 回答 1

10

代替

<inertia-link :href="'/download/'+slide.id" class="rounded-lg bg-gray-200 px-4 py-1">
                                    <Icon name="download"></Icon>
                                </inertia-link>

<a :href="'/download/' + slide.id" class="rounded-lg bg-gray-200 px-4 py-1">
    <Icon name="download"></Icon>
</a>

那么它将无法处理,inertia它将让您下载文件

于 2021-01-04T07:02:34.573 回答