Tuesday, May 15, 2018

Wrong path when downloading in Backpack CRUD view - development

Wrong path when downloading in Backpack CRUD view

i added an upload field in my CRUD Controller.
Upload works fine and file gets loaded in my /storage/private directory.

Here is filesystems.php file:

    'private' => [
        'driver' => 'local',
        'root' => storage_path('private')
    ],

Here are my custom functions in the File.php Model:

public static function boot()
{
    parent::boot();
    static::deleting(function($file) {
        Storage::disk('private')->delete($file->file);
    });
}

public function setFileAttribute($value)
{
    $attribute_name = "file";
    $disk = "private";
    $destination_path = "";
    // Cifratura del file
    file_put_contents($value->getRealPath(), file_get_contents($value->getRealPath()));
    $this->uploadFileToDisk($value, $attribute_name, $disk, $destination_path);
}

And here is my FileCRUDController.php code:

    $this->crud->addField(
    [   // Upload
        'name' => 'file',
        'label' => 'File to upload',
        'type' => 'upload',
        'upload' => true,
        'disk' => 'private'
    ]);

When i try to download the file, however, it tries to fetch it from http://localhost:8000/storage/myfile.png instead of http://localhost:8000/storage/private/myfile.png

What i’m doing wrong? Thank you very much.

I would also like to know if there is a way to hook a custom function instead downloading the file directly from the CRUD view. My files are encrypted and i need a controller that cares about decrypting before sending the files to the user.



from Laravel Questions and Answers https://laravelquestions.com/laravel/wrong-path-when-downloading-in-backpack-crud-view/
via Lzo Media

No comments:

Post a Comment