laravel/framework · error · RuntimeException

This driver does not support retrieving URLs.

Error message

This driver does not support retrieving URLs.

What it means

Thrown by FilesystemAdapter::url() when the underlying Flysystem adapter is not one of the URL-capable types and exposes no getUrl() method. Laravel can synthesize URLs for Local, FTP, and SFTP adapters, and for adapters (like S3) that implement getUrl(); any other custom adapter has no URL semantics, so the call is rejected.

Source

Thrown at src/Illuminate/Filesystem/FilesystemAdapter.php:797

     */
    public function url($path)
    {
        if (isset($this->config['prefix'])) {
            $path = $this->concatPathToUrl($this->config['prefix'], $path);
        }

        $adapter = $this->adapter;

        if (method_exists($adapter, 'getUrl')) {
            return $adapter->getUrl($path);
        } elseif (method_exists($this->driver, 'getUrl')) {
            return $this->driver->getUrl($path);
        } elseif ($adapter instanceof FtpAdapter || $adapter instanceof SftpAdapter) {
            return $this->getFtpUrl($path);
        } elseif ($adapter instanceof LocalAdapter) {
            return $this->getLocalUrl($path);
        } else {
            throw new RuntimeException('This driver does not support retrieving URLs.');
        }
    }

    /**
     * Get the URL for the file at the given path.
     *
     * @param  string  $path
     * @return string
     */
    protected function getFtpUrl($path)
    {
        return isset($this->config['url'])
            ? $this->concatPathToUrl($this->config['url'], $path)
            : $path;
    }

    /**
     * Get the URL for the file at the given path.

View on GitHub (pinned to bd6b5437e6)

Solutions

  1. Switch to a disk type that supports URLs (local with a url/serve config, s3, sftp, ftp).
  2. For a custom adapter, implement a getUrl($path) method on the adapter.
  3. Provide a 'url' config key so the local/ftp URL synthesis returns a value.
  4. Set the temporaryUrlCallback if you need synthetic URLs for an unsupported adapter.

Example fix

// before - custom adapter has no getUrl
$url = Storage::disk('memory')->url('file.txt');

// after - use a local disk with url config
// config/filesystems.php: 'public' => ['driver'=>'local','root'=>storage_path('app/public'),'url'=>'/storage']
$url = Storage::disk('public')->url('file.txt');
Defensive patterns

Strategy: validation

Validate before calling

$adapter = Storage::disk($name)->getAdapter();
if (! method_exists($adapter, 'getUrl')
    && ! $adapter instanceof \League\Flysystem\Local\LocalFilesystemAdapter
    && ! $adapter instanceof \League\Flysystem\Ftp\FtpAdapter
    && ! $adapter instanceof \League\Flysystem\PhpseclibV3\SftpAdapter) {
    throw new RuntimeException("Disk {$name} cannot generate URLs");
}

Type guard

function diskSupportsUrls(\Illuminate\Filesystem\FilesystemAdapter $disk): bool
{
    $a = $disk->getAdapter();
    return method_exists($a, 'getUrl')
        || $a instanceof \League\Flysystem\Local\LocalFilesystemAdapter
        || $a instanceof \League\Flysystem\Ftp\FtpAdapter
        || $a instanceof \League\Flysystem\PhpseclibV3\SftpAdapter;
}

Try / catch

try {
    $url = Storage::disk($name)->url($path);
} catch (\RuntimeException $e) {
    if (str_contains($e->getMessage(), 'does not support retrieving URLs')) {
        $url = null; // handle gracefully
    } else {
        throw $e;
    }
}

Prevention

When it happens

Trigger: Calling Storage::disk($name)->url($path) on a disk whose driver does not provide URLs - e.g. a memory adapter, a custom adapter without getUrl, or a generic Flysystem adapter not in the supported set.

Common situations: Calling url() on the default 'local' disk that lacks a 'url' config key in some setups; using a custom adapter registered via Storage::extend() that doesn't implement getUrl(); using an in-memory adapter in tests.

Related errors


AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06). Data as JSON: /data/errors/cf2dacfd64dd7edb.json. Report an issue: GitHub.