0

How to create a route that opens an external file?

As an example I have a xml file in my S3 bucket. (http://bucket_url/file.xml).

I need to create a route to open that file from my website. Like if I go to http://my_web_site_url.com/file.xml, it should view the file in my S3 bucket.

Is there a way to achieve this without calling a controller from the route file? Like can I say to open this file from this url in the routing file.

module_name.routing.yml

my_module.index:
path: '/file.xml'
defaults:
  _controller: 'Drupal\my_module\Controller\moduleController::view'
  _title: 'file View'
requirements:
  _permission: 'access content'
0

Is there a way to achieve this without calling a controller from the route file?

No, a route needs a controller, no exceptions. If you can find an existing controller/method that does what you need, reliably, then you should use that. If not, you'll need your own controller and method.

  • It says Unable to parse the controller name "FrameworkBundle:Redirect:urlRedirect". The document you have mentioned is for symfony. How do I use FrameworkBundle in Drupal – i am batman Jan 30 '18 at 11:25
  • Oh right, that's for bundles. Answer updated – Clive Jan 30 '18 at 11:48
  • You can also make a controller and do a TrustedUrlRedirect, but I don’t know how many files we are talking so it may not be a scalable solution. – Kevin Jan 30 '18 at 13:22

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.