Displaying dynamically generated images in Yesod

前端 未结 1 1107
闹比i
闹比i 2021-02-20 11:35

I\'m writing my first Yesod app. The application involves the user selecting to view a graph, dynamically generated based on data stored in a DB on the server. I know how to get

相关标签:
1条回答
  • 2021-02-20 12:04

    For a file on disk, you can use sendFile in your handler.

    getImageR = do
        -- ... save image data to disk somewhere
        sendFile typeJpeg "/path/to/file.jpg"
    

    For sending it from a ByteString in memory, use sendResponse.

    getImageR = do
        bytes <- -- generate image data
        sendResponse (typePng, toContent bytes)
    

    Make sure you specify the correct content type for your image.

    0 讨论(0)
提交回复
热议问题