Score:1

Link in URL field to Media File

in flag

Before the Update to the latest DruPal 8, we were able to link to public://foo/bar.pdf to a file which was in /sites/default/files/. No the public:// prefix does not work anymore in the URL input field.

We are still able to enter the full link, but this might have the downside that it needs to be updated when the file name changes.

error

We also tried /media/1337 but it shows a new page with the download link, while we need a direct download.

Can this still be accomplished?

ru flag
If this worked before, than it had exactly the same downside, a filename change will always brake this. You need [Media Entity Download](https://www.drupal.org/project/media_entity_download) for stable links to media entities.
Score:2
in flag

I think that the issue is that public:// is a PHP file stream wrapper defined by Drupal, which is a PHP language feature, and is not a URL, which is a publicly defined standard. The field is specifically requesting a URL.

The url /sites/default/files/<file name> should wok. Relative URLs are considered best practice.

The issue of changing file names is separate from the topic of file stream wrappers and URLs. A common method for mitigating this issue is to use the Pathauto module.

in flag
We tried to use relative links, but a `base:` prefix is prepend
in flag
The `base:` prefix is part of Drupal's URI processing scheme. From https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Url.php/function/Url%3A%3AfromUri/8.9.x: "For paths that are known not to be handled by the Drupal routing system (such as static files), use base: for the scheme to get a link relative to the Drupal base path."
in flag
Ah, so we could maybe use base: .. because we used just a "/" and base was inserted automagically.
in flag
No it is not working. If I enter base://sites/default/files/myfile.pdf it results in `<a href="base://sites/default/files/myfile.pdf">test</a>` and cannot be opened in the browser.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.