Skip to content

Commit bf8b223

Browse files
authored
Merge pull request #284 from weni-ai/fix/media-upload
fix: extract filename from URL path to avoid query params in media upload
2 parents ef6370f + b98c2aa commit bf8b223

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

WENI-CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
1.57.1
2+
----------
3+
* fix: extract filename from URL path to avoid query params in media upload
4+
15
1.57.0
26
----------
37
* refactor: Update wacOrderDetails structure to make Order field optional and adjust order handling logic for improved flexibility

handlers/facebookapp/facebookapp.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"net/http"
1414
"net/textproto"
1515
"net/url"
16-
"path/filepath"
16+
"path"
1717
"regexp"
1818
"strconv"
1919
"strings"
@@ -4363,7 +4363,11 @@ func requestWACMediaUpload(file []byte, mediaURL string, requestUrl string, mime
43634363
writer := multipart.NewWriter(body)
43644364

43654365
fileType := http.DetectContentType(file)
4366-
fileName := filepath.Base(mediaURL)
4366+
u, err := url.Parse(mediaURL)
4367+
if err != nil {
4368+
return "", logs, errors.Wrap(err, "invalid media URL")
4369+
}
4370+
fileName := path.Base(u.Path)
43674371

43684372
if fileType != mimeType || fileType == "application/octet-stream" || fileType == "application/zip" {
43694373
fileType = mimetype.Detect(file).String()

handlers/facebookapp/facebookapp_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,30 @@ var CachedSendTestCasesWAC = []ChannelSendTestCase{
17171717
},
17181718
},
17191719
SendPrep: setSendURL},
1720+
{Label: "Image Send with URL query params - filename should not contain params",
1721+
Text: "image caption",
1722+
URN: "whatsapp:250788123123",
1723+
Status: "W", ExternalID: "157b5e14568e8",
1724+
Attachments: []string{"image/jpeg:https://foo.bar/image.jpg?token=abc123&expires=9999"},
1725+
Responses: map[MockedRequest]MockedResponse{
1726+
{
1727+
Method: "POST",
1728+
Path: "/12345_ID/media",
1729+
BodyContains: `filename="image.jpg"`,
1730+
}: {
1731+
Status: 201,
1732+
Body: `{"id":"157b5e14568e8"}`,
1733+
},
1734+
{
1735+
Method: "POST",
1736+
Path: "/12345_ID/messages",
1737+
Body: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"image","image":{"id":"157b5e14568e8","caption":"image caption"}}`,
1738+
}: {
1739+
Status: 201,
1740+
Body: `{ "messages": [{"id": "157b5e14568e8"}] }`,
1741+
},
1742+
},
1743+
SendPrep: setSendURL},
17201744
}
17211745

17221746
var FailingCachedSendTestCasesWAC = []ChannelSendTestCase{

0 commit comments

Comments
 (0)