Browse Source

fix: 当缺少content-type头和文件后缀时自动检测mime type

Signed-off-by: changlin.shi <changlin.shi@ly.com>
pull/5936/head
changlin.shi 12 months ago
parent
commit
503ae6ad64
  1. 9
      weed/s3api/filer_multipart.go
  2. 2
      weed/s3api/s3api_object_handlers.go
  3. 3
      weed/s3api/s3api_object_multipart_handlers.go

9
weed/s3api/filer_multipart.go

@ -99,10 +99,13 @@ func (s3a *S3ApiServer) completeMultipartUpload(input *s3.CompleteMultipartUploa
for _, entry := range entries { for _, entry := range entries {
if strings.HasSuffix(entry.Name, ".part") && !entry.IsDirectory { if strings.HasSuffix(entry.Name, ".part") && !entry.IsDirectory {
partETag, found := findByPartNumber(entry.Name, completedParts)
partETag, isFirstPart, found := findByPartNumber(entry.Name, completedParts)
if !found { if !found {
continue continue
} }
if isFirstPart {
mime = entry.GetAttributes().Mime
}
entryETag := hex.EncodeToString(entry.Attributes.GetMd5()) entryETag := hex.EncodeToString(entry.Attributes.GetMd5())
if partETag != "" && len(partETag) == 32 && entryETag != "" && entryETag != partETag { if partETag != "" && len(partETag) == 32 && entryETag != "" && entryETag != partETag {
glog.Errorf("completeMultipartUpload %s ETag mismatch chunk: %s part: %s", entry.Name, entryETag, partETag) glog.Errorf("completeMultipartUpload %s ETag mismatch chunk: %s part: %s", entry.Name, entryETag, partETag)
@ -176,7 +179,7 @@ func (s3a *S3ApiServer) completeMultipartUpload(input *s3.CompleteMultipartUploa
return return
} }
func findByPartNumber(fileName string, parts []CompletedPart) (etag string, found bool) {
func findByPartNumber(fileName string, parts []CompletedPart) (etag string, firstPart, found bool) {
partNumber, formatErr := strconv.Atoi(fileName[:4]) partNumber, formatErr := strconv.Atoi(fileName[:4])
if formatErr != nil { if formatErr != nil {
return return
@ -198,7 +201,7 @@ func findByPartNumber(fileName string, parts []CompletedPart) (etag string, foun
break break
} }
} }
return parts[x+y].ETag, true
return parts[x+y].ETag, partNumber == 1, true
} }
func (s3a *S3ApiServer) abortMultipartUpload(input *s3.AbortMultipartUploadInput) (output *s3.AbortMultipartUploadOutput, code s3err.ErrorCode) { func (s3a *S3ApiServer) abortMultipartUpload(input *s3.AbortMultipartUploadInput) (output *s3.AbortMultipartUploadOutput, code s3err.ErrorCode) {

2
weed/s3api/s3api_object_handlers.go

@ -122,7 +122,7 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request)
} }
} else { } else {
uploadUrl := s3a.toFilerUrl(bucket, object) uploadUrl := s3a.toFilerUrl(bucket, object)
if objectContentType == "" {
if objectContentType == "" || objectContentType == "application/octet-stream" {
dataReader = mimeDetect(r, dataReader) dataReader = mimeDetect(r, dataReader)
} }

3
weed/s3api/s3api_object_multipart_handlers.go

@ -312,7 +312,8 @@ func (s3a *S3ApiServer) PutObjectPartHandler(w http.ResponseWriter, r *http.Requ
uploadUrl := fmt.Sprintf("http://%s%s/%s/%04d.part", uploadUrl := fmt.Sprintf("http://%s%s/%s/%04d.part",
s3a.option.Filer.ToHttpAddress(), s3a.genUploadsFolder(bucket), uploadID, partID) s3a.option.Filer.ToHttpAddress(), s3a.genUploadsFolder(bucket), uploadID, partID)
if partID == 1 && r.Header.Get("Content-Type") == "" {
contentType := r.Header.Get("Content-Type")
if partID == 1 && contentType == "" || contentType == "application/octet-stream" {
dataReader = mimeDetect(r, dataReader) dataReader = mimeDetect(r, dataReader)
} }

Loading…
Cancel
Save