How to include metadata with Vimeo upload API

327 Views Asked by At

I am working on aa API that uploads video file to Vimeo using Go tus approach. I could get the video created but not able to find a way to include metadata parameters that can be used to specify the name of video etc.

I am using github.com/eventials/go-tus for tus protocol and github.com/silentsokolov/go-vimeo/vimeo for sending APi requests to vimeo upload. Any pointers or help to upload videos on vimeo using thier API would be great help.

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)
}
0

There are 0 best solutions below