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 ...

  • 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 Aug 14 '17 at 15:16
1

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.

  • @berder Thanks for the lead. I've filed a bug here -- drupal.org/node/2902069 – Matt Aug 15 '17 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 Aug 15 '17 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 Aug 15 '17 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 Aug 21 '17 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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