contented: separate interior/exterior mime content-types

This commit is contained in:
mappu 2018-06-07 19:11:28 +12:00
parent 01351353e3
commit 382717d082

View File

@ -10,6 +10,7 @@ import (
"mime" "mime"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
"net/textproto"
telegram "github.com/go-telegram-bot-api/telegram-bot-api" 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{} uploadBody := bytes.Buffer{}
formValues := multipart.NewWriter(&uploadBody) 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 { if err != nil {
return "", err return "", err
} }
@ -116,7 +121,7 @@ func (this *NTFServer) ContentedUploadSync(fileId string, expectSizeBytes int64)
if err != nil { if err != nil {
return "", err return "", err
} }
req.Header.Set("Content-Type", fileContentType) req.Header.Set("Content-Type", `multipart/form-data`)
uploadResp, err := http.DefaultClient.Do(req) uploadResp, err := http.DefaultClient.Do(req)
if err != nil { if err != nil {
return "", fmt.Errorf("Upload failed: %s", err.Error()) return "", fmt.Errorf("Upload failed: %s", err.Error())