From dd2cc1acaf37efa7a58ce9df7cdc2d756ecfd473 Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev Date: Mon, 18 Oct 2021 16:27:57 +0500 Subject: [PATCH] fix https://github.com/chrislusf/seaweedfs/issues/2387 --- weed/s3api/s3api_object_handlers.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/weed/s3api/s3api_object_handlers.go b/weed/s3api/s3api_object_handlers.go index 16f5f34f3..296501516 100644 --- a/weed/s3api/s3api_object_handlers.go +++ b/weed/s3api/s3api_object_handlers.go @@ -39,9 +39,12 @@ func init() { func mimeDetect(r *http.Request, dataReader io.Reader) io.ReadCloser { mimeBuffer := make([]byte, 512) - dataReader.Read(mimeBuffer) - r.Header.Set("Content-Type", http.DetectContentType(mimeBuffer)) - return io.NopCloser(io.MultiReader(bytes.NewReader(mimeBuffer), dataReader)) + size, _ := dataReader.Read(mimeBuffer) + if size > 0 { + r.Header.Set("Content-Type", http.DetectContentType(mimeBuffer)) + return io.NopCloser(io.MultiReader(bytes.NewReader(mimeBuffer[:size]), dataReader)) + } + return io.NopCloser(dataReader) } func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request) {