@@ -2,6 +2,7 @@ package client
22
33import (
44 "bytes"
5+ "context"
56 "encoding/json"
67 "fmt"
78 "io"
@@ -294,7 +295,7 @@ func (c *Client) UploadFileContent(uploadID, fileName, contentType string, fileB
294295 body := & bytes.Buffer {}
295296 writer := multipart .NewWriter (body )
296297 partHeader := make (textproto.MIMEHeader )
297- partHeader .Set ("Content-Disposition" , multipart . FileContentDisposition ( "file" , fileName ))
298+ partHeader .Set ("Content-Disposition" , fmt . Sprintf ( `form-data; name= "file"; filename="%s"` , strings . NewReplacer ( `\` , `\\` , `"` , `\"` ). Replace ( fileName ) ))
298299 if contentType == "" {
299300 contentType = "application/octet-stream"
300301 }
@@ -323,10 +324,9 @@ func (c *Client) UploadFileContent(uploadID, fileName, contentType string, fileB
323324 fmt .Printf ("→ POST %s (multipart, %d bytes)\n " , url , body .Len ())
324325 }
325326
326- origTimeout := c .httpClient .Timeout
327- c .httpClient .Timeout = UploadTimeout
328- resp , err := c .httpClient .Do (req )
329- c .httpClient .Timeout = origTimeout
327+ ctx , cancel := context .WithTimeout (context .Background (), UploadTimeout )
328+ defer cancel ()
329+ resp , err := c .httpClient .Do (req .WithContext (ctx ))
330330 if err != nil {
331331 return nil , fmt .Errorf ("upload request failed: %w" , err )
332332 }
0 commit comments