Browse Source

GCS mime-type detection (#179)

Fixes #178
Thomas Blommaert 4 years ago
parent
commit
cd56039ab7
1 changed files with 5 additions and 0 deletions
  1. 5 0
      vfs/gcsfs.go

+ 5 - 0
vfs/gcsfs.go

@@ -7,6 +7,7 @@ import (
 	"errors"
 	"fmt"
 	"io"
+	"mime"
 	"net/http"
 	"os"
 	"path"
@@ -181,6 +182,10 @@ func (fs GCSFs) Create(name string, flag int) (*os.File, *PipeWriter, func(), er
 	obj := bkt.Object(name)
 	ctx, cancelFn := context.WithCancel(context.Background())
 	objectWriter := obj.NewWriter(ctx)
+	contentType := mime.TypeByExtension(path.Ext(name))
+	if contentType != "" {
+	    objectWriter.ObjectAttrs.ContentType = contentType
+	}
 	if len(fs.config.StorageClass) > 0 {
 		objectWriter.ObjectAttrs.StorageClass = fs.config.StorageClass
 	}