Search code examples
swiftserver-sidevaporleaf

How to show dynamic image with server side vapor swift?


i just newbie and want learn more about server side swift with vapor, now i am really stack on the show image dynamically with vapor swift. in my case. i have image on folder :

public -> images -> a.png , b.png

and i have name of image on my database, and i want to make get requests for show image on leaf file, with parameter name of my image, how to implement thats. Thanks a lot.


Solution

  • You can create route like so:

    drop.get("route") { request in
        return try self.drop.view.make("path/to/somepage", ["myimage": "/images/a.png"])
    }
    

    And in your somepage.leaf:

    <img src="#(myimage)">