Link to a static file in Yesod that does not have a Haskell ID

Given the Yesod default squadrode, with file upload by moving the downloaded file to the static directory, how can I link to a file in a static directory? For regular static files, the staticFiles splicing will generate an identifier that I can reference, but for user-uploaded files, obviously, I cannot hardcode these identifiers. I can do this manually using #{} splicing, but I was hoping there might be something a little more typical, even the only component checked is that I used the static/ prefix correctly.

+7
source share
1 answer

staticFiles generates a bunch of identifiers of type Route Static . Unfortunately, Haddock does not display information about related type families, so you cannot see the constructor in documents, but the only constructor available is StaticRoute :

 https://github.com/yesodweb/yesod/blob/master/yesod-static/Yesod/Static.hs#L142 

Two fields are path information and query string parameters. To create a link to /static/foo/bar?baz=bin , you can use:

 StaticRoute ["foo", "bar"] [("baz", "bin")] 

Normally, creating a query string parameter is optional, but staticFiles will use it to insert a hash value for caching purposes.

+8
source

All Articles