open-admin-org / open-admin

open-admin forked from z-song/laravel-ladmin. Removing jquery, now based on Bootstrap5, vanilla JS
https://open-admin.org
MIT License
245 stars 71 forks source link

Image field URL prefix duplicate #120

Open malikghanim opened 9 months ago

malikghanim commented 9 months ago

I installed open-admin by following the instructions step by step, Then I updated the config/filesystems.php and added the following :

'admin' => [
            'driver' => 'local',
            'root' => public_path('uploads'),
            'visibility' => 'public',
            'url' => env('APP_URL').'/uploads',
        ],

I update user record from admin http://localhost/admin/auth/users/1/edit and upload new avatar image

The Image is not showing, when I inspect the image I found that image url prefix duplicated as following http://localhost/uploads/http://localhost/uploads/images/User_icon-cp.png

How to resolve that issue?

Tech-Loyal commented 8 months ago

I have this same problem, have you found any solution for this?

AndreasMySch commented 7 months ago

Same problem here, also need a solution to this. Showing when inspecting: http://localhost/uploads/http://localhost/uploads/images/image.png

In admin.php file: 'upload' => [

    // Disk in `config/filesystem.php`.
    'disk' => 'admin',

    // Image and file upload path under the disk above.
    'directory' => [
        'image' => 'images',
        'file'  => 'files',
    ],
],

In filesystems.php file: 'disks' => [

    'admin' => [
        'driver' => 'local',
        'root' => public_path('uploads'),
        'url' => env('APP_URL').'/uploads',
        'visibility' => 'public',
    ],
    ...
    ..
subrata6630 commented 5 months ago

I have this same problem, have you found any solution for this?

drlafo commented 5 months ago

anyone?

zapsys commented 3 months ago

The problem occurs because the images path are saved with full path in the database. I solved this problem changing the 'upload' default disk to 'public' in config/admin.php file:

'upload' => [

        // Disk in config/filesystem.php.
        'disk' => 'public',

        // Image and file upload path under the disk above.
        'directory' => [
            'image' => 'images',
            'file'  => 'files',
        ],
    ],

In config/filesystem.php I setted the public path this way:

'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',    // set url
            'visibility' => 'public',
            'throw' => false,
        ],

This way the path is relative. This configuration worked for both localhost and live servers.

I implement this way in my Blade templates.

<img src="{{ asset('storage') . '/' . $image }}">

nlukic97 commented 4 weeks ago

I have been doing some testing and I might have found a solution.

I have the default admin_users table which has the avatarfield points to the image path. I also have a productstable where the imagefield points to the image path.

When editing one of these resources, the first one doesn't show a preview, whilst the second one does.

I have found a solution, its to add this line in /public/vendor/open-admin/fields/file-upload/file-upload.js file in the method initPreview:

image

It seems that, for some reason, the first resource already has the full url appended. While the second resource I created myself does not. Likely due to the fact that the input itself has the full path added to it for the first resource, but not for the newly created one.

I haven't managed to research a level higher to see what the issue may be, but this seems to be a safe solution to this problem.

EDIT: I have made additional changes to this file to suit my particular usecase.