contented: separate interior/exterior mime content-types
This commit is contained in:
parent
01351353e3
commit
382717d082
@ -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())
|
||||||
|
Loading…
Reference in New Issue
Block a user