如何从CloudFlare获取视频ID或使用生成的ID发布视频ID?

时间:2019-07-09 09:34:24

标签: go cloudflare

我使用Golang将视频上传到CloudFlare,我需要获取视频ID。

CloudFlare上传文档:link

我认为有两种方法: 1.视频上传后获取ID 2.上传ID为我在后端生成的视频

我花了几天的时间来寻找有关它的信息,但是我不能

这是我用于上传视频文件的Golang代码:

// get file from request
file, err := c.FormFile("file")
if err != nil {
    log.Errorf("get file error: %s", err)
    return c.JSONStatus(http.StatusBadRequest)
}

sourceFile, err := file.Open()
if err != nil {
    log.Errorf("open file error: %s", err)
    return c.JSONStatus(http.StatusInternalServerError)
}

fileBytes, err := ioutil.ReadAll(sourceFile)
if err != nil {
    fmt.Println(err)
}

// Here I generate Video ID (which I save to my DB)
fileName := uuid.New().String()

// Upload to CloudFlare
headers := make(http.Header)
headers.Add("X-Auth-Email", "***")
headers.Add("X-Auth-Key", "***")

config := &tus.Config{
    ChunkSize:           5 * 1024 * 1024,
    Resume:              false,
    OverridePatchMethod: false,
    Store:               nil,
    Header:              headers,
}

client, err := tus.NewClient("https://api.cloudflare.com/client/v4/accounts/"+ accountID +"/media", config) // I have tried to add /id after /media but I got 400 status code
if err != nil {
    log.Errorf("create upload client error: %s", err)
    return c.JSONStatus(http.StatusInternalServerError)
}

upload := tus.NewUploadFromBytes(fileBytes)

uploader, err := client.CreateUpload(upload)
if err != nil {
    log.Errorf("create upload error: %s", err)
    return c.JSONStatus(http.StatusInternalServerError)
}

0 个答案:

没有答案