diff --git a/backends/rapidpro/backend.go b/backends/rapidpro/backend.go index 0ed156238..a05ffe009 100644 --- a/backends/rapidpro/backend.go +++ b/backends/rapidpro/backend.go @@ -679,7 +679,7 @@ func (b *backend) ResolveMedia(ctx context.Context, mediaUrl string) (courier.Me mediaUUID := uuidRegex.FindString(u.Path) // if hostname isn't our media domain, or path doesn't contain a UUID, don't try to resolve - if u.Hostname() != b.config.MediaDomain || mediaUUID == "" { + if strings.Replace(u.Hostname(), fmt.Sprintf("%s.", b.config.S3Region), "", -1) != b.config.MediaDomain || mediaUUID == "" { return nil, nil } @@ -708,7 +708,7 @@ func (b *backend) ResolveMedia(ctx context.Context, mediaUrl string) (courier.Me } // if we found a media record but it doesn't match the URL, don't use it - if media == nil || media.URL() != mediaUrl { + if media == nil || (media.URL() != mediaUrl && media.URL() != strings.Replace(mediaUrl, fmt.Sprintf("%s.", b.config.S3Region), "", -1)) { return nil, nil } diff --git a/backends/rapidpro/backend_test.go b/backends/rapidpro/backend_test.go index fea332439..0d33b86fc 100644 --- a/backends/rapidpro/backend_test.go +++ b/backends/rapidpro/backend_test.go @@ -1366,6 +1366,19 @@ func (ts *BackendTestSuite) TestResolveMedia() { Alternates_: []*Media{}, }, }, + { // image upload that can be resolved + url: "http://nyaruka.us-east-1.s3.com/orgs/1/media/ec69/ec6972be-809c-4c8d-be59-ba9dbd74c977/test.jpg", + media: &Media{ + UUID_: "ec6972be-809c-4c8d-be59-ba9dbd74c977", + Path_: "/orgs/1/media/ec69/ec6972be-809c-4c8d-be59-ba9dbd74c977/test.jpg", + ContentType_: "image/jpeg", + URL_: "http://nyaruka.s3.com/orgs/1/media/ec69/ec6972be-809c-4c8d-be59-ba9dbd74c977/test.jpg", + Size_: 123, + Width_: 1024, + Height_: 768, + Alternates_: []*Media{}, + }, + }, { // same image upload, this time from cache url: "http://nyaruka.s3.com/orgs/1/media/ec69/ec6972be-809c-4c8d-be59-ba9dbd74c977/test.jpg", media: &Media{