Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

go - Load image using Gin

Tags:

go

I develop web application, But I can't load image. .css and .js file can be loaded by Static() method. Image is also same? How to load Image to web application using Gin?

router.Static("/css", "./css") // this is loading css file
router.Static("/js", "./js") // this is loading js file
// How to load Image?
like image 533
Diana Avatar asked Jul 31 '26 21:07

Diana


1 Answers

You may use StaticFile to serve a single file

router.StaticFile("/favicon.ico", "./resources/favicon.ico")

If you want to serve static image given its path,you may use it just like js and css

router.Static("/img", "./img")

or

import "github.com/gin-gonic/contrib/static"
.
.
.
router.Use(static.Serve("/img", static.LocalFile("./img", true)))
like image 193
Sarath Sadasivan Pillai Avatar answered Aug 04 '26 17:08

Sarath Sadasivan Pillai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!