Send files

Send a file, force-download to the client

// You can define your own "Content-Type" header also, after this function call
// for example: ctx.Response.Header.Set("Content-Type","thecontent/type")
SendFile(filename string, destinationName string)
package main

import "gopkg.in/kataras/iris.v5"

func main() {

    iris.Get("/servezip", func(c *iris.Context) {
        file := "./files/first.zip"
        c.SendFile(file, "saveAsName.zip")
    })

    iris.Listen(":8080")
}

You can also send bytes manually, which will be downloaded by the user:

package main

import "gopkg.in/kataras/iris.v5"

func main() {

    iris.Get("/servezip", func(c *iris.Context) {
        // read your file or anything
        var binary data[]
        ctx.Data(iris.StatusOK, data)
    })

    iris.Listen(":8080")
}

results matching ""

    No results matching ""