Fix PDF iframe sizing and properly encode Content-Disposition filename headers
All checks were successful
Automated Container Build / build-and-push (push) Successful in 1m1s
All checks were successful
Automated Container Build / build-and-push (push) Successful in 1m1s
This commit is contained in:
parent
e392da3699
commit
467fe30704
2 changed files with 7 additions and 3 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"mime"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
|
@ -1027,10 +1028,13 @@ func (h *FSHandler) Download(c *fiber.Ctx) error {
|
|||
c.Set("Accept-Ranges", "bytes")
|
||||
c.Set("Content-Type", mime.TypeByExtension(filepath.Ext(resolvedPath)))
|
||||
|
||||
safeNameQuote := strings.ReplaceAll(info.Name(), "\"", "\\\"")
|
||||
encodedName := url.PathEscape(info.Name())
|
||||
|
||||
if c.Query("download") == "true" {
|
||||
c.Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", info.Name()))
|
||||
c.Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"; filename*=UTF-8''%s", safeNameQuote, encodedName))
|
||||
} else {
|
||||
c.Set("Content-Disposition", fmt.Sprintf("inline; filename=\"%s\"", info.Name()))
|
||||
c.Set("Content-Disposition", fmt.Sprintf("inline; filename=\"%s\"; filename*=UTF-8''%s", safeNameQuote, encodedName))
|
||||
}
|
||||
|
||||
// Use Fiber's built-in SendFile which supports Range requests
|
||||
|
|
|
|||
Reference in a new issue