From 081a4d5aa8c3ae6cad2af45b7fb202044364dbeb Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Mon, 7 Nov 2022 15:41:53 +0300 Subject: [PATCH] allow specifying content-type while sending a file --- response.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/response.go b/response.go index 252353a..f0c6970 100644 --- a/response.go +++ b/response.go @@ -182,7 +182,7 @@ func (r *Response) Image(im image.Image) (QueryResponse, error) { return qr, err } - return r.AttachmentData(ImageAttachment, "meme.jpg", imageBytes) + return r.AttachmentData(ImageAttachment, "meme.jpg", "image/jpeg", imageBytes) } // Attachment sends an image, sound, video or a regular file to a chat. @@ -228,15 +228,14 @@ func createFormFile(filename string, w *multipart.Writer, contentType string) (i } // AttachmentData sends an image, sound, video or a regular file to a chat via an io.Reader. -func (r *Response) AttachmentData(dataType AttachmentType, filename string, filedata io.Reader) (QueryResponse, error) { +func (r *Response) AttachmentData( + dataType AttachmentType, filename string, contentType string, filedata io.Reader) (QueryResponse, error) { var qr QueryResponse filedataBytes, err := ioutil.ReadAll(filedata) if err != nil { return qr, err } - contentType := http.DetectContentType(filedataBytes[:512]) - fmt.Println("Content-type detected:", contentType) var body bytes.Buffer multipartWriter := multipart.NewWriter(&body)