Given a default Yesod scaffold, with file upload implemented by moving the uploaded file into the static directory, how do I link to the file in the static directory? For normal static files, the staticFiles splice will generate an identifier I can reference, but for user uploaded files obviously I cannot hardcode these identifiers. I can do this by manually using a #{} splice, but I was hoping there might be something a little more typesafe, even the only checkable component is that I used the static/ prefix correctly.
Given a default Yesod scaffold, with file upload implemented by moving the uploaded file
Share
staticFilesgenerates a bunch of identifiers with typeRoute Static. Unfortunately, Haddock doesn’t display the information on associated type families, so you can’t see the constructor in the docs, but the only constructor available isStaticRoute:The two fields are the path info and the query string parameters. So to create a link to
/static/foo/bar?baz=bin, you could use:Usually creating a query string parameter isn’t necessary, but
staticFileswill use it to insert a hash value for cache-busting purposes.