GCS mime-type detection (#179)

Fixes #178
This commit is contained in:
Thomas Blommaert 2020-09-28 21:52:18 +02:00 committed by GitHub
parent 55515fee95
commit cd56039ab7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
}