Routes containing periods don't work

Hey folks,

I’m writing a controller that retrieves files from Minio/S3 storage and serves them up at paths like /storage//.html. But, no matter what I do, my filenames get truncated to just “html” and don’t work. Here’s my route:

    get "/storage*filename", StorageController, :show

And a sample HTML snippet:

<iframe src="/storage/5b07dc02-cc8e-49d0-84c0-8e75081b730f/ig-ag302.html"></iframe>

Inspecting everything I can shows that the ig-ag302. is dropped from that URL when it hits the controller.

Any thoughts on how I can get this to work? I think I still want to serve it up from Phoenix because I want to retrieve the Document model from my database and check whether or not the user has access, but after that I want to stream the remaining URL path from the bucket as if it were a file. Unfortunately, I can’t just accept a format because, for instance, the HTML document generates lots of images, so I need links to those images to work as well.

Thanks for any suggestions.

That’s definitely not something phoenix does, so we’d need to see code that shows the issue (preferably minimal code that can be copy/pasted into IEX that demonstrates just the issue).

with this route and example, you will have the following params:

  params: %{"filename" => ["storage", "5b07dc02-cc8e-49d0-84c0-8e75081b730f", "ig-ag302.html"]},

Pay attention that filename in params is a list.

Which parts interest you? The last 2? In this case, you could match them directly:

get "/storage/:hash/:filename", StorageController, :show

which would translate into the following params in the controller:

params: %{"filename" => "ig-ag302.html", "hash" => "5b07dc02-cc8e-49d0-84c0-8e75081b730f"}
2 Likes