Come together with the global Drupal community in Rotterdam, 28 Sept – 1 Oct 2026. Sessions, contribution, connection, and Early Bird savings until 8 June.
Legend, thanks for reporting / looking at this. Could you perform one additional check please? Could you test this patch with the private:// schema? We might need another condition based on the schema type.
Also if you have some spare time you can experiment with this.
Move the url logic to .module like so:
use Drupal\Core\Url;
... etc etc
/**
* file_create_url in combination with Url::fromUri does
* not return a correct path for private files.
*/
function backup_db_link($uri) {
$scheme = \Drupal::service('file_system')->uriScheme($uri);
$path = Url::fromUri(file_create_url($uri));
return $path;
}
It will now generate the correct download links but you'll get an access denied if you try downloading the private one.
I don't have enough time to commit to it at the moment but if you do I think we're on to something here. Otherwise I'll pick it up later.
Here's a patch based on Alex's suggestion from #9.
However, since <?php Url::fromUri(file_create_url($uri)) ?> actually works for both `public` and `private` schemes, and it hasn't been used anywhere else I removed the <?php backup_db_link() ?> function.
I tested with both schemes, links are generated correctly.
I too get access denied error for private file download requests though.
Comments
Comment #2
swim commentedAre you exporting to your private file schema while having not defined a private schema yet?
Comment #3
swim commentedPlease reopen if you are still having issues.
Comment #4
Alex Andrascu commentedThis is indeed happening using default settings with Path set to public://backup_db
Attached patch fixes it.
Comment #5
Alex Andrascu commentedOops .module file added to patch by mistake. Patch re-attached.
Comment #6
swim commentedLegend, thanks for reporting / looking at this. Could you perform one additional check please? Could you test this patch with the private:// schema? We might need another condition based on the schema type.
Comment #7
Alex Andrascu commentedTrue, it now breaks the private schema. I'll be looking into it some point this week .
Comment #8
Alex Andrascu commentedComment #9
Alex Andrascu commentedAlso if you have some spare time you can experiment with this.
Move the url logic to .module like so:
use Drupal\Core\Url;... etc etc
change the controller historyOverview like so:
It will now generate the correct download links but you'll get an access denied if you try downloading the private one.
I don't have enough time to commit to it at the moment but if you do I think we're on to something here. Otherwise I'll pick it up later.
Comment #10
osmanHere's a patch based on Alex's suggestion from #9.
However, since
<?php Url::fromUri(file_create_url($uri)) ?>actually works for both `public` and `private` schemes, and it hasn't been used anywhere else I removed the<?php backup_db_link() ?>function.I tested with both schemes, links are generated correctly.
I too get access denied error for private file download requests though.
Comment #11
osmanComment #12
osmanbtw, I tried Private files download permission module to bypass access issues.
It seems that it can enable private file downloads without compromising access rules for rest of the private files: