|
@@ -2174,7 +2174,60 @@ func (s *Session) WebhookExecute(webhookID, token string, wait bool, data *Webho
|
|
|
uri += "?wait=true"
|
|
|
}
|
|
|
|
|
|
- response, err := s.RequestWithBucketID("POST", uri, data, EndpointWebhookToken("", ""))
|
|
|
+ var response []byte
|
|
|
+ if len(data.Files) > 0 {
|
|
|
+ body := &bytes.Buffer{}
|
|
|
+ bodywriter := multipart.NewWriter(body)
|
|
|
+
|
|
|
+ var payload []byte
|
|
|
+ payload, err = json.Marshal(data)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var p io.Writer
|
|
|
+
|
|
|
+ h := make(textproto.MIMEHeader)
|
|
|
+ h.Set("Content-Disposition", `form-data; name="payload_json"`)
|
|
|
+ h.Set("Content-Type", "application/json")
|
|
|
+
|
|
|
+ p, err = bodywriter.CreatePart(h)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if _, err = p.Write(payload); err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for i, file := range data.Files {
|
|
|
+ h := make(textproto.MIMEHeader)
|
|
|
+ h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file%d"; filename="%s"`, i, quoteEscaper.Replace(file.Name)))
|
|
|
+ contentType := file.ContentType
|
|
|
+ if contentType == "" {
|
|
|
+ contentType = "application/octet-stream"
|
|
|
+ }
|
|
|
+ h.Set("Content-Type", contentType)
|
|
|
+
|
|
|
+ p, err = bodywriter.CreatePart(h)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if _, err = io.Copy(p, file.Reader); err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ err = bodywriter.Close()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ response, err = s.request("POST", uri, bodywriter.FormDataContentType(), body.Bytes(), uri, 0)
|
|
|
+ } else {
|
|
|
+ response, err = s.RequestWithBucketID("POST", uri, data, uri)
|
|
|
+ }
|
|
|
if !wait || err != nil {
|
|
|
return
|
|
|
}
|