Skip to content

Commit

Permalink
file upload: use client-provided mime type when auto-detection fails
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Apr 15, 2023
1 parent a5076b6 commit dda74cd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions server/hdl_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func largeFileReceive(wrt http.ResponseWriter, req *http.Request) {
return
}

file, _, err := req.FormFile("file")
file, header, err := req.FormFile("file")
if err != nil {
logs.Info.Println("media upload: invalid multipart form", err)
if strings.Contains(err.Error(), "request body too large") {
Expand All @@ -263,12 +263,21 @@ func largeFileReceive(wrt http.ResponseWriter, req *http.Request) {
writeHttpResponse(ErrUnknown(msgID, "", now), err)
return
}

mimeType := http.DetectContentType(buff)
// If DetectContentType failed, use user-provided content type.
if mimeType == "application/octet-stream" {
if contentType := header.Header.Get("Content-Type"); contentType != "" {
mimeType = contentType
}
}

fdef := &types.FileDef{
ObjHeader: types.ObjHeader{
Id: store.Store.GetUidString(),
},
User: uid.String(),
MimeType: http.DetectContentType(buff),
MimeType: mimeType,
}
fdef.InitTimes()

Expand Down

0 comments on commit dda74cd

Please sign in to comment.