PHP error FileUrlGenerator

Created on 29 November 2024, 24 days ago

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.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡΅πŸ‡ΉPortugal saidatom Lisbon

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024