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)
| 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. |
| 341 | func (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 |
nothing calls this directly
no test coverage detected