Skip to content

Commit b8da96c

Browse files
committed
fix: set Content-Disposition header for media served from filesystem
set inline for videos, images and pdfs and attachment for rest
1 parent 3d76cce commit b8da96c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

cmd/media.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ func handleServeMedia(r *fastglue.Request) error {
185185
consts := app.consts.Load().(*constants)
186186
switch consts.UploadProvider {
187187
case "fs":
188+
disposition := "attachment"
189+
190+
// Keep certain content types inline.
191+
if strings.HasPrefix(media.ContentType, "image/") ||
192+
strings.HasPrefix(media.ContentType, "video/") ||
193+
media.ContentType == "application/pdf" {
194+
disposition = "inline"
195+
}
196+
197+
r.RequestCtx.Response.Header.Set("Content-Type", media.ContentType)
198+
r.RequestCtx.Response.Header.Set("Content-Disposition", fmt.Sprintf(`%s; filename="%s"`, disposition, media.Filename))
199+
188200
fasthttp.ServeFile(r.RequestCtx, filepath.Join(ko.String("upload.fs.upload_path"), uuid))
189201
case "s3":
190202
r.RequestCtx.Redirect(app.media.GetURL(uuid), http.StatusFound)

0 commit comments

Comments
 (0)