Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions modules/storage/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"crypto/tls"
"fmt"
"io"
"mime"
"net/http"
"net/url"
"os"
"path"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -285,8 +287,16 @@ func (m *MinioStorage) URL(path, name, method string, serveDirectReqParams url.V
if err != nil {
return nil, err
}
// TODO it may be good to embed images with 'inline' like ServeData does, but we don't want to have to read the file, do we?
reqParams.Set("response-content-disposition", "attachment; filename=\""+quoteEscaper.Replace(name)+"\"")
// Detect content type by extension name
contentDisposition := "attachment; filename=\"" + quoteEscaper.Replace(name) + "\""
ext := filepath.Ext(name)
mimetype := mime.TypeByExtension(ext)
reqParams.Set("response-content-type", mimetype)
if mimetype == "application/pdf" || strings.HasPrefix(mimetype, "image/") {
contentDisposition = "inline"
}

reqParams.Set("response-content-disposition", contentDisposition)
expires := 5 * time.Minute
if method == http.MethodHead {
u, err := m.client.PresignedHeadObject(m.ctx, m.bucket, m.buildMinioPath(path), expires, reqParams)
Expand Down