-
Notifications
You must be signed in to change notification settings - Fork 42
/
file_upload.go
51 lines (45 loc) · 1.31 KB
/
file_upload.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
51
package datasource
import (
"io"
"strconv"
"github.com/bububa/oceanengine/marketing-api/model"
)
// FileUploadRequest 数据源文件上传 API Request
type FileUploadRequest struct {
// AdvertiserID 广告主ID
AdvertiserID uint64 `json:"advertiser_id,omitempty"`
// File 文件
File io.Reader `json:"file,omitempty"`
// Filename 文件名
Filename string `json:"filename,omitempty"`
// FileSignature 文件MD5
FileSignature string `json:"file_signature,omitempty"`
}
// Encode implement UploadReqeust interface
func (r FileUploadRequest) Encode() []model.UploadField {
ret := make([]model.UploadField, 0, 3)
ret = append(ret, model.UploadField{
Key: "advertiser_id",
Value: strconv.FormatUint(r.AdvertiserID, 10),
})
ret = append(ret, model.UploadField{
Key: "file",
Value: r.Filename,
Reader: r.File,
})
ret = append(ret, model.UploadField{
Key: "file_signature",
Value: r.FileSignature,
})
return ret
}
// FileUploadResponse 数据文件上传API Response
type FileUploadResponse struct {
model.BaseResponse
Data *FileUploadResponseData `json:"data,omitempty"`
}
// FileUploadResponseData json返回值
type FileUploadResponseData struct {
// FilePath 文件路径,包含作为文件唯一标识的字符串(14天后文件路径过期)
FilePath string `json:"file_path,omitempty"`
}