[英]Laravel & inertia.js file download
I uploaded a file to the database and created Storage link using "php artisan storage:link" and everything work perfectly but when I want to download the file I face this error我将文件上传到数据库并使用“php artisan storage:link”创建了存储链接,一切正常,但是当我想下载文件时,我遇到了这个错误
here's my code这是我的代码
route路线
Route::get('/download/{id}', [\App\Http\Controllers\SubjectController::class, 'downloadFile'])->name('subject.download');
Vue.js Vue.js
<inertia-link :href="'/download/'+slide.id" class="rounded-lg bg-gray-200 px-4 py-1">
<Icon name="download"></Icon>
</inertia-link>
the Controller Controller
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');
}
replace代替
<inertia-link :href="'/download/'+slide.id" class="rounded-lg bg-gray-200 px-4 py-1">
<Icon name="download"></Icon>
</inertia-link>
to至
<a :href="'/download/' + slide.id" class="rounded-lg bg-gray-200 px-4 py-1">
<Icon name="download"></Icon>
</a>
then it will not handle by inertia
and it will let you download file那么它不会被
inertia
处理,它会让你下载文件
I hava the issue.我有这个问题。 Looking in inertia I was thinking to use inertia::location() to redirect for a page no inertia.
看着惯性,我想使用惯性::location() 来重定向页面没有惯性。 But I don't if will work.
但我不知道是否会工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.