-
Notifications
You must be signed in to change notification settings - Fork 17
/
open_api_media.go
50 lines (44 loc) · 1.07 KB
/
open_api_media.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package dingtalk
import (
"io"
"net/url"
)
type MediaUploadResponse struct {
OpenAPIResponse
Type string
MediaID string `json:"media_id"`
CreatedAt int64 `json:"created_at"`
}
type MediaDownloadFileResponse struct {
OpenAPIResponse
MediaID string
Writer io.Writer
}
type uploadFile struct {
FileName string
FieldName string
Reader io.Reader
}
// 上传媒体文件
func (dtc *DingTalkClient) MediaUpload(mediaType string, fileName string, reader io.Reader) (MediaUploadResponse, error) {
var data MediaUploadResponse
upload := &uploadFile{
FieldName: "media",
FileName: fileName,
Reader: reader,
}
params := url.Values{}
params.Add("type", mediaType)
err := dtc.httpRPC("media/upload", params, upload, &data)
return data, err
}
// 获取媒体文件
func (dtc *DingTalkClient) MediaDownloadFile(mediaID string, write io.Writer) error {
var data MediaDownloadFileResponse
data.MediaID = mediaID
data.Writer = write
params := url.Values{}
params.Add("media_id", mediaID)
err := dtc.httpRPC("media/downloadFile", params, nil, &data)
return err
}