7
0
gaore-common-sdk-go/services/oss/multipart_init.go

65 lines
1.8 KiB
Go
Raw Permalink Normal View History

package oss
import (
"crypto/md5"
"encoding/hex"
"fmt"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
"time"
)
const (
multipartUploadKeys = "b4471b940d98"
)
type InitMultipartUploadRequest struct {
*requests.JsonRequest
UploadType string `position:"Json" field:"upload_type"`
TargetType string `position:"Json" field:"target_type"`
TargetName string `position:"Json" field:"target_name"`
FileHash string `position:"Json" field:"file_hash"`
Filepath string `position:"Json" field:"filepath"`
ExtInfo string `position:"Json" field:"ext_info"`
}
type InitMultipartUploadResponse struct {
*responses.BaseResponse
Code int `json:"code"`
Msg string `json:"msg"`
Data struct {
FileUploaded bool `json:"file_uploaded"`
UploadId string `json:"upload_id,omitempty"`
Links []Link `json:"links,omitempty"`
2024-07-23 09:22:59 +08:00
Hash string `json:"hash,omitempty"`
Url string `json:"url,omitempty"`
Filepath string `json:"filepath,omitempty"`
FileName string `json:"filename,omitempty"`
} `json:"data"`
}
type Link struct {
Href string `json:"href"`
Rel string `json:"rel"`
Method string `json:"method"`
}
func CreateInitMultipartUploadRequest() (req *InitMultipartUploadRequest) {
ts := fmt.Sprintf("%d", time.Now().Unix())
m := md5.Sum([]byte(ts + multipartUploadKeys))
sign := hex.EncodeToString(m[:])
req = &InitMultipartUploadRequest{
JsonRequest: &requests.JsonRequest{},
}
2024-10-12 15:27:57 +08:00
req.InitWithApiInfo(HOST, VERSION, "/api/upload/multipart/init?_ts="+ts+"&_sign="+sign)
return
}
func CreateInitMultipartUploadResponse() (resp *InitMultipartUploadResponse) {
resp = &InitMultipartUploadResponse{
BaseResponse: &responses.BaseResponse{},
}
return resp
}