allow specifying content-type while sending a file
This commit is contained in:
commit
23f3b3123d
@ -182,7 +182,7 @@ func (r *Response) Image(im image.Image) (QueryResponse, error) {
|
|||||||
return qr, err
|
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.
|
// 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.
|
// 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
|
var qr QueryResponse
|
||||||
|
|
||||||
filedataBytes, err := ioutil.ReadAll(filedata)
|
filedataBytes, err := ioutil.ReadAll(filedata)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return qr, err
|
return qr, err
|
||||||
}
|
}
|
||||||
contentType := http.DetectContentType(filedataBytes[:512])
|
|
||||||
fmt.Println("Content-type detected:", contentType)
|
|
||||||
|
|
||||||
var body bytes.Buffer
|
var body bytes.Buffer
|
||||||
multipartWriter := multipart.NewWriter(&body)
|
multipartWriter := multipart.NewWriter(&body)
|
||||||
|
Loading…
Reference in New Issue
Block a user