From e4931816ef7e0d25761e1ef3aca39500214b41a8 Mon Sep 17 00:00:00 2001 From: aby913 Date: Wed, 10 Sep 2025 20:02:50 +0800 Subject: [PATCH] fix: pdf preview --- pkg/hertz/biz/handler/api/raw/raw_service.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/hertz/biz/handler/api/raw/raw_service.go b/pkg/hertz/biz/handler/api/raw/raw_service.go index cef32be6..bc417119 100644 --- a/pkg/hertz/biz/handler/api/raw/raw_service.go +++ b/pkg/hertz/biz/handler/api/raw/raw_service.go @@ -10,13 +10,14 @@ import ( raw "files/pkg/hertz/biz/model/api/raw" "files/pkg/models" "fmt" + "mime" + "strings" + "time" + "github.com/cloudwego/hertz/pkg/app" "github.com/cloudwego/hertz/pkg/common/utils" "github.com/cloudwego/hertz/pkg/protocol/consts" "k8s.io/klog/v2" - "mime" - "strings" - "time" ) // RawMethod . @@ -74,6 +75,8 @@ func RawMethod(ctx context.Context, c *app.RequestContext) { if rawInline == "true" { if rawMeta == "true" { c.SetContentType("application/json; charset=utf-8") + } else { + c.SetContentType(common.MimeTypeByExtension(file.FileName)) } c.Header("Cache-Control", "private") c.Header("Content-Disposition", mime.FormatMediaType("inline", map[string]string{ @@ -93,7 +96,6 @@ func RawMethod(ctx context.Context, c *app.RequestContext) { } if !file.IsCloud { - c.Header("Content-Disposition", "attachment; filename="+file.FileName) c.Header("Last-Modified", file.FileModified.UTC().Format(time.RFC1123)) ifMatch := string(c.GetHeader("If-Modified-Since")) if ifMatch != "" {