Serve files from Context

// SendFile sends a file as an attachment, that is downloaded and
// saved locally from client.
// Note that compression can be registered through `ctx.CompressWriter(true)`
// or `app.Use(iris.Compression)`.
// Use `ServeFile` if a file should be served as a page asset instead.
SendFile(filename string, destinationName string) error
// SendFileWithRate same as `SendFile` but it can throttle the speed of reading
// and though writing the file to the client.
SendFileWithRate(src, destName string, limit float64, burst int) error

Usage

Force-Send a file to the client:

func handler(ctx iris.Context) {
	src := "./files/first.zip"
	ctx.SendFile(src, "client.zip")
}

Limit download speed to ~50Kb/s with a burst of 100KB:

func handler(ctx iris.Context) {
    src := "./files/big.zip"
    // optionally, keep it empty to resolve the filename based on the "src".
	dest := "" 

	limit := 50.0 * iris.KB
	burst := 100 * iris.KB
	ctx.SendFileWithRate(src, dest, limit, burst)
}

Usage

Last updated

Was this helpful?