diff --git a/attachments.go b/attachments.go index 3a8da80a2..5d112c478 100644 --- a/attachments.go +++ b/attachments.go @@ -115,7 +115,7 @@ func FetchAndStoreAttachment(ctx context.Context, b Backend, channel Channel, at // prioritize to use the response content type header if provided contentTypeHeader := trace.Response.Header.Get("Content-Type") - if contentTypeHeader != "" { + if contentTypeHeader != "" && contentTypeHeader != "application/octet-stream" { mimeType, _, _ = mime.ParseMediaType(contentTypeHeader) if extension == "" { extensions, err := mime.ExtensionsByType(mimeType) diff --git a/attachments_test.go b/attachments_test.go index e4f3f4e8d..dc8c47c5a 100644 --- a/attachments_test.go +++ b/attachments_test.go @@ -23,6 +23,9 @@ func TestFetchAndStoreAttachment(t *testing.T) { "http://mock.com/media/hello2": { httpx.NewMockResponse(200, map[string]string{"Content-Type": "image/jpeg"}, testJPG), }, + "http://mock.com/media/hello3": { + httpx.NewMockResponse(200, map[string]string{"Content-Type": "application/octet-stream"}, testJPG), + }, "http://mock.com/media/hello.mp3": { httpx.NewMockResponse(502, nil, []byte(`My gateways!`)), }, @@ -82,6 +85,12 @@ func TestFetchAndStoreAttachment(t *testing.T) { assert.NoError(t, err) assert.Equal(t, &courier.Attachment{ContentType: "unavailable", URL: "http://mock.com/media/hello.pdf"}, att) + att, err = courier.FetchAndStoreAttachment(ctx, mb, mockChannel, "http://mock.com/media/hello3", clog) + assert.NoError(t, err) + assert.Equal(t, "image/jpeg", att.ContentType) + assert.Equal(t, "https://backend.com/attachments/338ff339-5663-49ed-8ef6-384876655d1b.jpg", att.URL) + assert.Equal(t, 17301, att.Size) + // an actual error on our part should be returned as an error mb.SetStorageError(errors.New("boom"))