I have a D9 (now upgrading to D10) in a subdirectory. The latest 3.1 version stopped working (it did work on the D9 compatible version).

I tracked this down to some logic where the replacement of the public path was done using the request host instead of the Drupal base url.

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

hanoii created an issue. See original summary.

hanoii’s picture

Status: Active » Needs review

MR!93 added.

smustgrave’s picture

Status: Needs review » Needs work

Possible dup https://www.drupal.org/project/stage_file_proxy/issues/3499660

Either way probably should have a test

hanoii’s picture

Hmm, definitely a dupe, I tried searching for something similar but my keyword-fu was probably not on its peak. I will comment there, I think this patch is cleaner and rely on a core function rather than string replacements.

hanoii’s picture

Rebased

lisotton’s picture

Status: Needs work » Closed (duplicate)
Related issues: +#3508533: Image not found while trying to generate derivative image

Issue was already fixed in the latest version of the module.

hanoii’s picture

Title: Doesn't work if Drupal is served from a subdirectory » simplify DownloadManager::filePublicPath()
Category: Bug report » Task
Status: Closed (duplicate) » Needs review

I kind of feel that this is a better fix, currently the logic is doing things that are really not necessary.

diff --git a/src/DownloadManager.php b/src/DownloadManager.php
index ae73c0c2cb17e267bf318f6a428810a10d2908b3..bf5a00e1a7762606b52ea5c6402f69d0874fa728 100644
--- a/src/DownloadManager.php
+++ b/src/DownloadManager.php
@@ -140,11 +140,7 @@ final class DownloadManager implements DownloadManagerInterface {
    * {@inheritdoc}
    */
   public function filePublicPath(): string {
-    $request = $this->requestStack->getCurrentRequest();
-    $filesDir = PublicStream::baseUrl();
-    $host = $request->getSchemeAndHttpHost();
-    $basePath = $request->getBasePath();
-    return str_replace($host . $basePath . '/', '', $filesDir);
+    return PublicStream::basePath();
   }
 
   /**

Why do all that to remove things from baseUrl() when base basePath() already gives yo what you want?

You are calling baseUrl() that is $base_url + basePath() to then remove $base_url.

cgoffin’s picture

Here also a patch to use in your projects.

cgoffin’s picture

And the fix is working for me. Thanks!

smustgrave’s picture

If someone wants to RTBC I can merge.

smustgrave’s picture

Version: 3.1.x-dev » 4.0.x-dev
Status: Needs review » Needs work
smustgrave’s picture

Status: Needs work » Postponed (maintainer needs more info)

Actually can this one get a summary update about why it’s still needed please

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Can always be re-opened but please address #13 if you do.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.