Displaying dynamically generated images in Yesod

前端 未结 1 1108
闹比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)
提交回复
热议问题