all repos — homestead @ 3923eb14921e25a708c2eed30c333614e8f54ff4

Code for my website

sqlite: check/sniff file content type

Alan Pearce
commit

3923eb14921e25a708c2eed30c333614e8f54ff4

parent

cb0c1a6f85c4577b242228a7310d137bf461b30f

1 file changed, 5 insertions(+), 0 deletions(-)

jump to
M internal/storage/sqlite/writer.gointernal/storage/sqlite/writer.go
@@ -6,6 +6,7 @@ "fmt"
"hash/fnv" "io" "mime" + "net/http" "path/filepath" "time"
@@ -130,6 +131,10 @@ return r.LastInsertId()
} func (s *Writer) storeFile(urlID int64, file *storage.File) (int64, error) { + if file.ContentType == "" { + file.ContentType = http.DetectContentType(file.Encodings["identity"].Bytes()) + s.log.Warn("file has no content type, sniffing", "path", file.Path, "sniffed", file.ContentType) + } r, err := s.queries.insertFile.Exec( sql.Named("url_id", urlID), sql.Named("content_type", file.ContentType),