Yôkai's avatar

Storage::disk()->url() returning bad link

Hello ! I have a form that uploads an image inside a custom disk which have been configured in the filesystems.php:

filesystems.php

    'disks' => [
    ...
        'ranks'  => [
            'driver' => 'local',
            'root' => storage_path('app/public/ranks'),
            'visibility' => 'public',
        ],
    ...
    ],

When I want to access to my file url, I'm doing this:

return Storage::disk('ranks')->url($this->name); //$this->name is the filename

It works not bad, it's returning me "/storage/myfile.ext" but I'm expecting to have "/storage/app/public/ranks/myfile.ext". I can read on documentation:

Note: When using the local driver, be sure to create a symbolic link at public/storage which points to the storage/app/public directory.

But even after this I got this issue, where did I wrong ? Thanks for help

0 likes
7 replies
Swaz's avatar

@YÔKAI I'm having the same issue. Did you ever figure this out?

//filesystems.php
'disks' => [
    'custom' => [
        'driver' => 'local',
        'root' => storage_path('app/custom'),
    ],
]
// Expected: /storage/app/custom/file.pdf
// Result:   /storage/app/file.pdf
$path = Storage::disk('custom')->url('file.pdf')

Swaz's avatar

@ejdelmonico I don't think this is a sym link issue.

What were looking at is the path that gets returned from Storage::disk()->url(), it's not returning what you would expect.

ejdelmonico's avatar

In response to your original question, the url's are correct if you are storing the files locally, with the filesystem local drive. You save to disk in `/storage/app/public/your-disk and after you run the artisan link command you access by public/storage/file.name.

Swaz's avatar

@ejdelmonico Oh gotcha, I didn't release it was expecting you to make the files public. I was trying with a private directory, so guess I'll just use storage_path()instead.

ejdelmonico's avatar

You can still use the built in storage path and make any particular file invisible to the public. The whole system is pretty flexible in that nature. The only issues I have run into is with S3 storage. But, as you know, nothing works all the time.

Please or to participate in this conversation.