API page: https://api.drupal.org/api/drupal/core%21includes%21file.inc/function/fi...

We're working on a REST endpoint that reads a field that contains a private file, gets the private://blahandblue from the entity via getFileUri(). Then we pass it to create_file_url() to actually get a usable external URL.

create_file_url uses the stream_wrapper_manager_service which actually sends data to the http stream, which means the REST response can no longer be valid.

Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php throws the following (on line 157):

Uncaught PHP Exception LogicException: "The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\\rest\\ResourceResponse."

Either there should be another method to get the URL (whether there is already one or or not is different) or this one ought to be renamed. But a method called create_file_url should not be sending anything to http stream, because it is doing more than creating the URL.

Comments

meezaan created an issue. See original summary.

meezaan’s picture

Issue summary: View changes

Version: 8.2.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kim.pepper’s picture

Status: Active » Postponed (maintainer needs more info)

Do you mean file_create_url? It was deprecated in 9.3.0 and was removed in Drupal 10.0.0. https://www.drupal.org/node/2940031 Can you verify the issue exists in a supported version of Drupal?

larowlan’s picture

Category: Bug report » Support request
Status: Postponed (maintainer needs more info) » Closed (works as designed)
Issue tags: -private files, -create_file_url +Bug Smash Initiative

This sounds like you're using it wrong, you need to call it in a render context or be sure to collect the metadata from the generated URL