MCPcopy
hub / github.com/gofiber/fiber / Download

Method Download

res.go:341–363  ·  view source on GitHub ↗

Download transfers the file from path as an attachment. Typically, browsers will prompt the user for download. By default, the Content-Disposition header filename= parameter is the filepath (this typically appears in the browser dialog). Override this default with the filename parameter.

(file string, filename ...string)

Source from the content-addressed store, hash-verified

339// By default, the Content-Disposition header filename= parameter is the filepath (this typically appears in the browser dialog).
340// Override this default with the filename parameter.
341func (r *DefaultRes) Download(file string, filename ...string) error {
342 var fname string
343 if len(filename) > 0 {
344 fname = filepath.Base(filename[0])
345 } else {
346 fname = filepath.Base(file)
347 }
348 fname = sanitizeFilename(fname)
349 fname = fallbackFilenameIfInvalid(fname)
350 app := r.c.app
351 var quoted string
352 if app.isASCII(fname) {
353 quoted = app.quoteString(fname)
354 } else {
355 quoted = app.quoteRawString(fname)
356 }
357 disp := `attachment; filename="` + quoted + `"`
358 if !app.isASCII(fname) {
359 disp += `; filename*=UTF-8''` + url.PathEscape(fname)
360 }
361 r.setCanonical(HeaderContentDisposition, disp)
362 return r.SendFile(file)
363}
364
365// Response return the *fasthttp.Response object
366// This allows you to use all fasthttp response methods

Callers

nothing calls this directly

Calls 7

setCanonicalMethod · 0.95
SendFileMethod · 0.95
sanitizeFilenameFunction · 0.85
isASCIIMethod · 0.80
quoteStringMethod · 0.80
quoteRawStringMethod · 0.80

Tested by

no test coverage detected