How to force plug.static to run a check

I have a downloads directory where I put pdf file to be displayed.
I want to make sure the the request to display the file came from a specific ip
because I am using plug.static I cannot put a plug to check the request
My question: is there is a way to pass the download request to go thru a check routine to make sure that the IP is correct or just any other check?

Not directly, but you can simply place a plug in front of Plug.Static that matches on the static path and will halt the request is not from the authorized IP.

You can also serve those files through a controller with something like.

send_file(conn, 200, path_to_file)

That way You can use any checks that apply to a controller.
It gives You the advantage to access files from anywhere.

1 Like

I tried that. didn’t work

This command will download the pdf file into the client computer. Don’t want that
Thanks anyway

Just in the meantime I copied the source from Plug.Static, changed into a new plug, change it and used this plug instead

This would give You a path to access the file, as if You used a static path… but that’s fine if You can do it by hacking plug static :slight_smile:

The problem with your solution (for me) is that when you are using chrome you have to save the file on your local disk first. My customer didn’t like that

Thanks for your answer

In that case, it is possible to use send_download instead, with the correct content_type :slight_smile:

lookup the content-disposition header