Skip to content

Commit 7750aa6

Browse files
authored
blob/gcsblob: Ensure driver sets Content-Type auto-detection properly (#3381)
1 parent 6ca965e commit 7750aa6

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

blob/blob.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,14 +1083,15 @@ func (b *Bucket) NewWriter(ctx context.Context, key string, opts *WriterOptions)
10831083
opts = &WriterOptions{}
10841084
}
10851085
dopts := &driver.WriterOptions{
1086-
CacheControl: opts.CacheControl,
1087-
ContentDisposition: opts.ContentDisposition,
1088-
ContentEncoding: opts.ContentEncoding,
1089-
ContentLanguage: opts.ContentLanguage,
1090-
ContentMD5: opts.ContentMD5,
1091-
BufferSize: opts.BufferSize,
1092-
MaxConcurrency: opts.MaxConcurrency,
1093-
BeforeWrite: opts.BeforeWrite,
1086+
CacheControl: opts.CacheControl,
1087+
ContentDisposition: opts.ContentDisposition,
1088+
ContentEncoding: opts.ContentEncoding,
1089+
ContentLanguage: opts.ContentLanguage,
1090+
ContentMD5: opts.ContentMD5,
1091+
BufferSize: opts.BufferSize,
1092+
MaxConcurrency: opts.MaxConcurrency,
1093+
BeforeWrite: opts.BeforeWrite,
1094+
DisableContentTypeDetection: opts.DisableContentTypeDetection,
10941095
}
10951096
if len(opts.Metadata) > 0 {
10961097
// Services are inconsistent, but at least some treat keys

blob/driver/driver.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ type WriterOptions struct {
100100
// Metadata holds key/value strings to be associated with the blob.
101101
// Keys are guaranteed to be non-empty and lowercased.
102102
Metadata map[string]string
103+
// When true, the driver should attempt to disable any automatic
104+
// content-type detection that the provider applies on writes with an
105+
// empty ContentType.
106+
DisableContentTypeDetection bool
103107
// BeforeWrite is a callback that must be called exactly once before
104108
// any data is written, unless NewTypedWriter returns an error, in
105109
// which case it should not be called.

blob/gcsblob/gcsblob.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ func (b *bucket) NewTypedWriter(ctx context.Context, key string, contentType str
628628
w.ChunkSize = bufferSize(opts.BufferSize)
629629
w.Metadata = opts.Metadata
630630
w.MD5 = opts.ContentMD5
631+
w.ForceEmptyContentType = opts.DisableContentTypeDetection
631632
return w
632633
}
633634

0 commit comments

Comments
 (0)