1

Should we be able to add a url_alias (in D8 from /admin/config/search/path) for a private file?
Right now it allows me to add an alias (and I can see that it is being rendered in the front end) but it generates a 404.

In my particular case the path for the uploaded file is ... /system/files/2017-08/1.pdf

A related, but different question, includes ...

1
  • I don't think so. The way the private file system works, I don't see this being possible. But I might be totally wrong :D
    – user21641
    Commented Aug 14, 2017 at 15:16

1 Answer 1

2

Interesting question.

In theory, every routed path should be able to have an alias because it runs through \Drupal\Core\PathProcessor\PathProcessorAlias::processInbound() before routing, which converts it back to the system path.

However, private files, and image styles are special and quite weird. Because the routing system does not really support having an argument with / and doesn't know how to properly map that to a single argument (Not sure if that is still true or if there would be a better way now with more recent symfony versions), we have a workaround.

That workaround for private files is \Drupal\system\PathProcessor\PathProcessorFiles::processInbound(), which converts the full private path to just "/system/files" with file as a query argument.

The problem is now that those two run on the same event, and PathProcessorFiles runs first, at that point, the path is still the alias and does not match system/files/$something.

I'd say this is a bug and the priority of the service definitions should be adjusted for this. That is path_processor.files (currently 200) and path_processor_alias ( currently 100). Setting the first to 99 and clearing caches makes it work for me.

I'd suggest you open a core issue for this, I suspect nobody tried this yet.

4
  • @berder Thanks for the lead. I've filed a bug here -- drupal.org/node/2902069
    – Matt
    Commented Aug 15, 2017 at 12:13
  • What 'ya said made a lot of sense. I filed the bug and was going to go submit a patch, but I'm unable to reproduce a fix w/ the solution you suggested (after clearing cache).
    – Matt
    Commented Aug 15, 2017 at 13:42
  • My fixed definitely worked for me locally. I'd suggest you start by uploading a patch in the issue and we continue there.
    – Berdir
    Commented Aug 15, 2017 at 17:53
  • I went back and tested again and confirmed the approach you described worked and added a patch as requested. Didn't identify any side-effects. Thanks for your help!
    – Matt
    Commented Aug 21, 2017 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.