UniSharp / laravel-filemanager

Media gallery with CKEditor, TinyMCE and Summernote support. Built on Laravel file system.
https://unisharp.github.io/laravel-filemanager/
MIT License
2.08k stars 723 forks source link

i try download a file from s3 but show the next error (The file "folder/share/file.zip" does not exist) #883

Open SergioWiesner opened 4 years ago

SergioWiesner commented 4 years ago

Please check the following instructions before submitting a bug :

And provide the followings :

2infinity-gh commented 4 years ago

I have the same issue... very annoying

daydevelops commented 3 years ago

Has there been a solution for this?

daydevelops commented 3 years ago

The Problem

The download route calls an endpoint which uses the getDownload() method on the DownloadController which looks like this:


    public function getDownload()
    {
        $file = $this->lfm->setName(request('file'));

        if (!Storage::disk($this->helper->config('disk'))->exists($file->path('storage'))) {
            abort(404);
        }

        return response()->download($file->path('absolute'));
    }

response()->download() is a symphony component which eventually calls the native php function is_file() to determine if the file exists. This obviously does not check which disk you are using, so anything other than local will fail.

A Solution

To get around this, I overrode the getDownload() method on the package controller. Here are my registered routes:

Route::group(['prefix' => 'laravel-filemanager', 'middleware' => ['web','auth','access-files','file-permissions']], function () {
    \UniSharp\LaravelFilemanager\Lfm::routes();
    // override download route
    Route::get('/download', [FileManagerController::class, 'download']);
});

And the new controller method:

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Storage;
use UniSharp\LaravelFilemanager\Controllers\LfmController;

class FileManagerController extends LfmController
{
    public function download() {
        $file = $this->lfm->setName(request('file'));

        if (!Storage::disk($this->helper->config('disk'))->exists($file->path('storage'))) {
            abort(404);
        }

        return Storage::disk($this->helper->config('disk'))->download($file->path('storage'));
    }
}
dorqa95 commented 3 years ago

Thank you so much, it's helped me out <3