upload media

This commit is contained in:
cn-hideyoshi 2024-12-11 19:23:29 +08:00
parent bc5999ba6f
commit d7d4c2e3f4
1 changed files with 22 additions and 1 deletions

View File

@ -115,7 +115,28 @@ func (o *OaSdk) UploadFileByByte(file []byte, ext string) (string, string, error
if err != nil {
return "", "", err
}
res, err := http.Post(UploadOaMedia, writer.FormDataContentType(), body)
token, err := o.getAccessToken()
if err != nil {
return "", "", err
}
postType := ""
if ext == ".jpg" || ext == ".png" || ext == ".gif" || ext == ".jpeg" {
postType = "image"
} else if ext == ".mp4" {
postType = "video"
} else if ext == ".mp3" {
postType = "voice"
}
if postType == "" {
return "", "", fmt.Errorf("不支持的文件类型")
}
res, err := http.Post(
fmt.Sprintf("%s?access_token=%s&type=%s", UploadOaMedia, token, postType),
writer.FormDataContentType(),
body,
)
if err != nil {
return "", "", err
}