Storage: Mime type detection (#52512)

* Storage: implement mime type detection

* lint
This commit is contained in:
Artur Wierzbicki
2022-07-25 11:30:20 +04:00
committed by GitHub
parent 1e3135b18a
commit d9db155394
9 changed files with 169 additions and 29 deletions

View File

@@ -2,6 +2,7 @@ package store
import (
"context"
"mime"
"path/filepath"
"github.com/grafana/grafana/pkg/infra/filestorage"
@@ -41,10 +42,17 @@ func (s *standardStorageService) sanitizeUploadRequest(ctx context.Context, user
return nil, err
}
// we have already validated that the file contents match the extension in `./validate.go`
mimeType := mime.TypeByExtension(filepath.Ext(req.Path))
if mimeType == "" {
grafanaStorageLogger.Info("failed to find mime type", "path", req.Path)
mimeType = "application/octet-stream"
}
return &filestorage.UpsertFileCommand{
Path: storagePath,
Contents: contents,
MimeType: req.MimeType,
MimeType: mimeType,
CacheControl: req.CacheControl,
ContentDisposition: req.ContentDisposition,
Properties: req.Properties,