Skip to content

Commit

Permalink
Fix MSC3870 media uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Sep 15, 2022
1 parent f39552c commit 89d15e3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1293,12 +1293,21 @@ type ReqUploadMedia struct {
func (cli *Client) UploadMedia(data ReqUploadMedia) (*RespMediaUpload, error) {
if data.UploadURL != "" {
retries := cli.DefaultHTTPRetries
if data.ContentBytes == nil {
// Can't retry with a reader
retries = 0
}
for {
if data.Content == nil {
data.Content = bytes.NewReader(data.ContentBytes)
}
cli.Logger.Debugfln("Uploading media to external URL %s", data.UploadURL)
req, err := http.NewRequest(http.MethodPut, data.UploadURL, data.Content)
if err != nil {
return nil, err
}
// Tell the next retry to create a new reader from ContentBytes
data.Content = nil
req.Header.Set("Content-Type", data.ContentType)

resp, err := http.DefaultClient.Do(req)
Expand Down

0 comments on commit 89d15e3

Please sign in to comment.