Problem/Motivation

When attempting to use an external URL (e.g., ftp://example.com/file.txt) as the value for a file_url field, the following error is triggered:

Drupal\Core\File\Exception\InvalidStreamWrapperException in Drupal\Core\File\FileUrlGenerator->doGenerateString() (line 105 of core/lib/Drupal/Core/File/FileUrlGenerator.php).

This occurs because the FileUrlGenerator expects a supported stream wrapper (public://, private://, etc.) but does not recognize or handle external URL schemes like ftp://.

Steps to reproduce

  1. Create a field of type file_url.
  2. Add content with an external URL value, such as ftp://example.com/file.txt.
  3. Attempt to view the content.
  4. The error mentioned above is displayed.

Proposed resolution

Update the RemoteFile class to handle external URL schemes by implementing a createFileUrl() method. This method will return the file’s URI directly using getFileUri(), bypassing the unsupported stream wrapper logic.

Issue fork file_url-3490692

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

saidatom created an issue. See original summary.

saidatom’s picture

Title: PHP error FileUrlGenerator » Handle External URL Schemes Like ftp:// in File URL Fields Without Errors

saidatom’s picture

Status: Active » Needs review
alorenc’s picture

Assigned: Unassigned » alorenc
alorenc’s picture

Looks good, thanks

alorenc’s picture

Assigned: alorenc » Unassigned
Status: Needs review » Reviewed & tested by the community

claudiu.cristea made their first commit to this issue’s fork.

claudiu.cristea’s picture

Status: Reviewed & tested by the community » Fixed

Thank you

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.