0

我正在开发一个使用 Go tus 方法将视频文件上传到 Vimeo 的 API。我可以创建视频,但无法找到一种方法来包含可用于指定视频名称等的元数据参数。

我将 github.com/eventials/go-tus 用于 tus 协议,将 github.com/silentsokolov/go-vimeo/vimeo 用于将 APi 请求发送到 vimeo 上传。使用他们的 API 在 vi​​meo 上上传视频的任何指示或帮助都会有很大帮助。

package main

import (
    "fmt"
    "os"
    tus "github.com/eventials/go-tus"
    "github.com/silentsokolov/go-vimeo/vimeo"
    "golang.org/x/oauth2"
)

type Uploader struct{}

func (u Uploader) UploadFromFile(c *vimeo.Client, uploadURL string, f *os.File) error {
    tusClient, err := tus.NewClient(uploadURL, nil)
    if err != nil {
        return err
    }

    upload, err := tus.NewUploadFromFile(f)

    metdata := make(map[string]string)
    metdata["name"] = "Callout_Video"

    upload.Metadata = metdata
    uploader := tus.NewUploader(tusClient, uploadURL, upload, 0)

    return uploader.Upload()
}

func main() {

    config := vimeo.Config{
        Uploader: &Uploader{},
    }

    ts := oauth2.StaticTokenSource(
        &oauth2.Token{AccessToken: "xxxxxxxxx"},
    )
    tc := oauth2.NewClient(oauth2.NoContext, ts)

    client := vimeo.NewClient(tc, &config)

    filePath := "Test_Video.mp4"

    f, _ := os.Open(filePath)

    fmt.Println(f.Name())
    video, resp, _ := client.Users.UploadVideo("", f)

    fmt.Println(video.Name)
    fmt.Println(resp)
}
4

0 回答 0