diff --git a/contented.go b/contented.go index f647d5c..3708e66 100644 --- a/contented.go +++ b/contented.go @@ -10,6 +10,7 @@ import ( "mime" "mime/multipart" "net/http" + "net/textproto" telegram "github.com/go-telegram-bot-api/telegram-bot-api" ) @@ -95,7 +96,11 @@ func (this *NTFServer) ContentedUploadSync(fileId string, expectSizeBytes int64) uploadBody := bytes.Buffer{} formValues := multipart.NewWriter(&uploadBody) - filePart, err := formValues.CreateFormFile("f", fileName) + // Adapted from (mime/multipart)Writer.CreateFormFile to support a custom interior content type + multipartFileHeader := make(textproto.MIMEHeader) + multipartFileHeader.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%s"; filename="%s"`, "f", fileName)) + multipartFileHeader.Set("Content-Type", fileContentType) + filePart, err := formValues.CreatePart(multipartFileHeader) if err != nil { return "", err } @@ -116,7 +121,7 @@ func (this *NTFServer) ContentedUploadSync(fileId string, expectSizeBytes int64) if err != nil { return "", err } - req.Header.Set("Content-Type", fileContentType) + req.Header.Set("Content-Type", `multipart/form-data`) uploadResp, err := http.DefaultClient.Do(req) if err != nil { return "", fmt.Errorf("Upload failed: %s", err.Error())