作者 yangfu

视频点播修改

@@ -30,6 +30,9 @@ func (this *VodController) CreateUploadVideo() { @@ -30,6 +30,9 @@ func (this *VodController) CreateUploadVideo() {
30 msg = m 30 msg = m
31 return 31 return
32 } 32 }
  33 + if len(request.FileName) == 0 {
  34 + request.FileName = aliyun.DefaultVideoFileName
  35 + }
33 header := controllers.GetRequestHeader(this.Ctx) 36 header := controllers.GetRequestHeader(this.Ctx)
34 msg = protocol.NewReturnResponse(upload.CreateUploadVideo(header, request)) 37 msg = protocol.NewReturnResponse(upload.CreateUploadVideo(header, request))
35 } 38 }
@@ -13,3 +13,9 @@ const ( @@ -13,3 +13,9 @@ const (
13 FileVoice = "voice" 13 FileVoice = "voice"
14 FileVideo = "video" 14 FileVideo = "video"
15 ) 15 )
  16 +
  17 +const (
  18 + DefaultVideoFileName = "test.mp4"
  19 + DefaultVoiceFileName = "test.mp3"
  20 + DefaultImageFileName = "test.jpg"
  21 +)
  1 +package aliyun
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 +)
  6 +
  7 +/*
  8 +AK AccessKey 完全访问权限
  9 +STS (Security Token Service) 临时访问控制
  10 +*/
  11 +
  12 +var (
  13 + Endpoint string = beego.AppConfig.String("end_point")
  14 + BucketName string = beego.AppConfig.String("bucket_name")
  15 + //BucketNameCdn string = beego.AppConfig.String("bucket_name_cdn")
  16 + //EndpointCdn string = beego.AppConfig.String("end_point_cdn")
  17 +)
  18 +
  19 +//type OssSts struct{
  20 +//
  21 +//}
  22 +
  23 +//func NewSTS(){
  24 +// client,_ :=oos.NewClientWithAccessKey(RegionID,AccessKeyID,AccessKeySecret)
  25 +// client.DoAction()
  26 +//}
@@ -3,6 +3,7 @@ package aliyun @@ -3,6 +3,7 @@ package aliyun
3 //创建视频上传凭证 3 //创建视频上传凭证
4 /*CreateUploadVideo */ 4 /*CreateUploadVideo */
5 type CreateUploadVideoRequest struct { 5 type CreateUploadVideoRequest struct {
  6 + FileName string `position:"Query" name:"fileName"`
6 } 7 }
7 8
8 type CreateUploadVideoResponse struct { 9 type CreateUploadVideoResponse struct {
1 package aliyun 1 package aliyun
2 2
3 type CreateUploadImageRequest struct { 3 type CreateUploadImageRequest struct {
  4 + FileName string `json:"fileName"`
4 } 5 }
5 6
6 type CreateUploadImageResponse struct { 7 type CreateUploadImageResponse struct {
@@ -10,6 +10,7 @@ import ( @@ -10,6 +10,7 @@ import (
10 comm_time "gitlab.fjmaimaimai.com/mmm-go/gocomm/time" 10 comm_time "gitlab.fjmaimaimai.com/mmm-go/gocomm/time"
11 "opp/internal/utils" 11 "opp/internal/utils"
12 "path" 12 "path"
  13 + "path/filepath"
13 "time" 14 "time"
14 ) 15 )
15 16
@@ -39,10 +40,13 @@ func InitVodClient(accessKeyId string, accessKeySecret string) (client *vod.Clie @@ -39,10 +40,13 @@ func InitVodClient(accessKeyId string, accessKeySecret string) (client *vod.Clie
39 //获取视频上传地址和凭证,并创建视频信息 40 //获取视频上传地址和凭证,并创建视频信息
40 func CreateUploadVideo(client *vod.Client, r *CreateUploadVideoRequest) (response *CreateUploadVideoResponse, err error) { 41 func CreateUploadVideo(client *vod.Client, r *CreateUploadVideoRequest) (response *CreateUploadVideoResponse, err error) {
41 request := vod.CreateCreateUploadVideoRequest() 42 request := vod.CreateCreateUploadVideoRequest()
42 - request.Title = getFileName(FileVideo, "video_file.mp4")  
43 - request.FileName = getFileName(FileVideo, "video_file.mp4")  
44 - //request.CoverURL = "http://img.alicdn.com/tps/TB1qnJ1PVXXXXXCXXXXXXXXXXXX-700-700.png"  
45 - //request.Tags = "tag1,tag2" 43 + filePath := getFileName(FileVideo, r.FileName)
  44 + if filepath.Ext(r.FileName) == "mp3" {
  45 + filePath = getFileName(FileVideo, r.FileName)
  46 + }
  47 + request.Title = filePath
  48 + request.FileName = filePath
  49 + //request.StorageLocation = filepath.Base(filePath)
46 request.AcceptFormat = "JSON" 50 request.AcceptFormat = "JSON"
47 rsp, err := client.CreateUploadVideo(request) 51 rsp, err := client.CreateUploadVideo(request)
48 if err != nil { 52 if err != nil {
@@ -60,9 +64,12 @@ func CreateUploadVideo(client *vod.Client, r *CreateUploadVideoRequest) (respons @@ -60,9 +64,12 @@ func CreateUploadVideo(client *vod.Client, r *CreateUploadVideoRequest) (respons
60 //获取图片上传地址和凭证,并创建视频信息 64 //获取图片上传地址和凭证,并创建视频信息
61 func CreateUploadImage(client *vod.Client, r *CreateUploadImageRequest) (response *CreateUploadImageResponse, err error) { 65 func CreateUploadImage(client *vod.Client, r *CreateUploadImageRequest) (response *CreateUploadImageResponse, err error) {
62 request := vod.CreateCreateUploadImageRequest() 66 request := vod.CreateCreateUploadImageRequest()
63 - request.ImageType = "cover" 67 + filePath := getFileName(FileImage, r.FileName)
  68 + request.ImageType = "default"
  69 + request.Title = filePath
  70 + request.ImageExt = filepath.Ext(r.FileName)
64 request.AcceptFormat = "JSON" 71 request.AcceptFormat = "JSON"
65 - request.ImageExt = "jpg" 72 + //request.StorageLocation = filepath.Base(request.Title)
66 rsp, err := client.CreateUploadImage(request) 73 rsp, err := client.CreateUploadImage(request)
67 if err != nil { 74 if err != nil {
68 return 75 return
@@ -145,6 +145,9 @@ func CreateUploadVideo(header *protocol.RequestHeader, request *aliyun.CreateUpl @@ -145,6 +145,9 @@ func CreateUploadVideo(header *protocol.RequestHeader, request *aliyun.CreateUpl
145 return 145 return
146 } 146 }
147 rsp, err = aliyun.CreateUploadVideo(client, request) 147 rsp, err = aliyun.CreateUploadVideo(client, request)
  148 + if err != nil {
  149 + log.Error(err)
  150 + }
148 return 151 return
149 } 152 }
150 153