feat(lagoon/attach): export UploadWriterOptions for blob writers that bypass Store (quick-261106-d20)
- attach.UploadWriterOptions (was the unexported uploadWriterOptions) gives code that writes an upload to the bucket itself the same Content-Type and Content-Disposition: attachment for non-inline types that attach.Store stores - writeBlob calls it; Store behaviour unchanged - TestUploadWriterOptions table test - lagoon README, docs/database/attachments.md and docs/services/storage.md describe it for writers that bypass attach.Store
This commit is contained in:
@@ -33,9 +33,14 @@ func IsInlineContentType(contentType string) bool {
|
||||
return err == nil && inlineContentTypes[strings.ToLower(mediaType)]
|
||||
}
|
||||
|
||||
// uploadWriterOptions are the blob writer options of an upload: the content
|
||||
// type, plus the attachment disposition when the type is not inline.
|
||||
func uploadWriterOptions(contentType string) *blob.WriterOptions {
|
||||
// UploadWriterOptions returns the blob writer options of an upload: the
|
||||
// content type, plus Content-Disposition: attachment (no filename parameter)
|
||||
// for every type IsInlineContentType does not report as inline. Store writes
|
||||
// with these options. Code that writes an upload to the bucket itself, with
|
||||
// NewWriter or WriteAll, passes the sniffed type (the value stored in
|
||||
// content_type) and names the file with DiskExtension, so its blob is served
|
||||
// like one Store wrote. Each call returns a new value the caller may extend.
|
||||
func UploadWriterOptions(contentType string) *blob.WriterOptions {
|
||||
opts := &blob.WriterOptions{ContentType: contentType}
|
||||
if !IsInlineContentType(contentType) {
|
||||
opts.ContentDisposition = attachmentDisposition
|
||||
|
||||
Reference in New Issue
Block a user