go get -u github.com/tencentcloud/tencentcloud-sdk-gogo get -u github.com/tencentyun/cos-go-sdk-v5go get -u github.com/tencentyun/vod-go-sdk
import ("github.com/tencentyun/vod-go-sdk")client := &vod.VodUploadClient{}client.SecretId = "your secretId"client.SecretKey = "your secretKey"
import ("github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common")req := vod.NewVodUploadRequest()req.MediaFilePath = common.StringPtr("/data/video/Wildlife.mp4")
rsp, err := client.Upload("ap-guangzhou", req)if err != nil {fmt.Println(err)return}fmt.Println(*rsp.Response.FileId)fmt.Println(*rsp.Response.MediaUrl)
package mainimport ("github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common""github.com/tencentyun/vod-go-sdk""fmt")func main() {client := &vod.VodUploadClient{}client.SecretId = "your secretId"client.SecretKey = "your secretKey"req := vod.NewVodUploadRequest()req.MediaFilePath = common.StringPtr("/data/video/Wildlife.mp4")req.CoverFilePath = common.StringPtr("/data/video/Wildlife-cover.png")rsp, err := client.Upload("ap-guangzhou", req)if err != nil {fmt.Println(err)return}fmt.Println(*rsp.Response.FileId)fmt.Println(*rsp.Response.MediaUrl)fmt.Println(*rsp.Response.CoverUrl)}
package mainimport ("github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common""github.com/tencentyun/vod-go-sdk""fmt")func main() {client := &vod.VodUploadClient{}client.SecretId = "your secretId"client.SecretKey = "your secretKey"req := vod.NewVodUploadRequest()req.MediaFilePath = common.StringPtr("/data/video/Wildlife.mp4")req.Procedure = common.StringPtr("Your Proceducre Name")rsp, err := client.Upload("ap-guangzhou", req)if err != nil {fmt.Println(err)return}fmt.Println(*rsp.Response.FileId)fmt.Println(*rsp.Response.MediaUrl)}
package mainimport ("github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common""github.com/tencentyun/vod-go-sdk""fmt")func main() {client := &vod.VodUploadClient{}client.SecretId = "your secretId"client.SecretKey = "your secretKey"req := vod.NewVodUploadRequest()req.MediaFilePath = common.StringPtr("/data/video/Wildlife.mp4")req.SubAppId = common.Uint64Ptr(101)rsp, err := client.Upload("ap-guangzhou", req)if err != nil {fmt.Println(err)return}fmt.Println(*rsp.Response.FileId)fmt.Println(*rsp.Response.MediaUrl)}
package mainimport ("github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common""github.com/tencentyun/vod-go-sdk""fmt")func main() {client := &vod.VodUploadClient{}client.SecretId = "your secretId"client.SecretKey = "your secretKey"req := vod.NewVodUploadRequest()req.MediaFilePath = common.StringPtr("/data/video/Wildlife.mp4")req.StorageRegion = common.StringPtr("ap-chongqing")rsp, err := client.Upload("ap-guangzhou", req)if err != nil {fmt.Println(err)return}fmt.Println(*rsp.Response.FileId)fmt.Println(*rsp.Response.MediaUrl)}
ConcurrentUploadNumber
参数进行指定。package mainimport ("github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common""github.com/tencentyun/vod-go-sdk""fmt")func main() {client := &vod.VodUploadClient{}client.SecretId = "your secretId"client.SecretKey = "your secretKey"req := vod.NewVodUploadRequest()req.MediaFilePath = common.StringPtr("/data/video/Wildlife.mp4")req.ConcurrentUploadNumber = common.Uint64Ptr(5)rsp, err := client.Upload("ap-guangzhou", req)if err != nil {fmt.Println(err)return}fmt.Println(*rsp.Response.FileId)fmt.Println(*rsp.Response.MediaUrl)}
package mainimport ("github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common""github.com/tencentyun/vod-go-sdk""fmt")func main() {client := &vod.VodUploadClient{}client.SecretId = "Credentials TmpSecretId"client.SecretKey = "Credentials TmpSecretKey"client.Token = "Credentials Token"req := vod.NewVodUploadRequest()req.MediaFilePath = common.StringPtr("/data/video/Wildlife.mp4")rsp, err := client.Upload("ap-guangzhou", req)if err != nil {fmt.Println(err)return}fmt.Println(*rsp.Response.FileId)fmt.Println(*rsp.Response.MediaUrl)}
package mainimport ("github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common""github.com/tencentyun/vod-go-sdk""fmt""net/http""net/url")func main() {client := &vod.VodUploadClient{}client.SecretId = "your secretId"client.SecretKey = "your secretKey"proxyUrl, _ := url.Parse("your proxy url")client.Transport = &http.Transport{Proxy: http.ProxyURL(proxyUrl),}req := vod.NewVodUploadRequest()req.MediaFilePath = common.StringPtr("/data/video/Wildlife.mp4")rsp, err := client.Upload("ap-guangzhou", req)if err != nil {fmt.Println(err)return}fmt.Println(*rsp.Response.FileId)fmt.Println(*rsp.Response.MediaUrl)}
../
)。在调用 SDK 上传接口时,MediaFilePath
参数填写 manifest 路径,SDK 会解析出相关的媒体文件列表一并上传。package mainimport ("github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common""github.com/tencentyun/vod-go-sdk""fmt")func main() {client := &vod.VodUploadClient{}client.SecretId = "your secretId"client.SecretKey = "your secretKey"req := vod.NewVodUploadRequest()req.MediaFilePath = common.StringPtr("/data/video/prog_index.m3u8")rsp, err := client.Upload("ap-guangzhou", req)if err != nil {fmt.Println(err)return}fmt.Println(*rsp.Response.FileId)fmt.Println(*rsp.Response.MediaUrl)fmt.Println(*rsp.Response.CoverUrl)}
VodUploadClient
属性名称 | 属性描述 | 类型 | 必填 |
SecretId | 云 API 密钥 ID。 | String | 是 |
SecretKey | 云 API 密钥 Key。 | String | 是 |
VodUploadRequest
属性名称 | 属性描述 | 类型 | 必填 |
MediaFilePath | 待上传的媒体文件路径。必须为本地路径,不支持 URL。 | String 指针 | 是 |
SubAppId | uint64 指针 | 否 | |
MediaType | String 指针 | 否 | |
MediaName | 上传后的媒体名称,若不填默认采用 MediaFilePath 的文件名。 | String 指针 | 否 |
CoverFilePath | 待上传的封面文件路径。必须为本地路径,不支持 URL。 | String 指针 | 否 |
CoverType | String 指针 | 否 | |
Procedure | String 指针 | 否 | |
ExpireTime | String 指针 | 否 | |
ClassId | int64 指针 | 否 | |
SourceContext | 来源上下文,用于透传用户请求信息,上传回调接口将返回该字段值,最长250个字符。 | String 指针 | 否 |
StorageRegion | String 指针 | 否 | |
ConcurrentUploadNumber | 分片并发数,针对大文件分片时有效。 | Integer | 否 |
VodUploadResponse
属性名称 | 属性描述 | 类型 |
Response | 上传返回结果信息。 | struct |
Response.FileId | 媒体文件的唯一标识。 | String 指针 |
Response.MediaUrl | 媒体播放地址。 | String 指针 |
Response.CoverUrl | 媒体封面地址。 | String 指针 |
Response.RequestId | 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 | String 指针 |
VodUploadClient.Upload(region string, request *VodUploadRequest)
参数名称 | 参数描述 | 类型 | 必填 |
region | String | 是 | |
request | 上传请求。 | VodUploadRequest 指针 | 是 |
状态码 | 含义 |
InternalError | 内部错误。 |
InvalidParameter.ExpireTime | 参数值错误:过期时间。 |
InvalidParameterValue.CoverType | 参数值错误:封面类型。 |
InvalidParameterValue.MediaType | 参数值错误:媒体类型。 |
InvalidParameterValue.SubAppId | 参数值错误:子应用 ID。 |
InvalidParameterValue.VodSessionKey | 参数值错误:点播会话。 |
ResourceNotFound | 资源不存在。 |
本页内容是否解决了您的问题?