DEMOS / Content Type and Headers

In a pinch, you can use Nitrogen to dynamically serve content other than HTML. The image to the right is served as raw data from a Nitrogen module.

Also, this shows how you can use the wf:header/2 function to dynamically set the headers, and in this case, use the "Content-Disposition" header to make the browser download a file rather than displaying it in the browser directly. We also demonstrate the wf:download_as/1 function, which is a shortcut to set the "Content-Disposition" header.

View the source code of demos_contenttype_image.erl to see how it's done.

View Module Source
Copyright © 2008-2024 Nitrogen Web Framework. Released under the MIT License.