LinkedIn Vector Asset API 不断返回 400 错误请求

LinkedIn Vector Asset API keeps returning 400 Bad Request

我有以下方法使用 registerUpload 请求提供的 URL 和 Headers 将媒体“上传”到 LinkedIn。我一直在尝试各种不同的方法来尝试让它工作但没有成功。事实上,当我尝试上传单张图片时,这个 returns 400 Bad Request 响应。在这种特殊情况下,文档似乎没有太大帮助。我在这里做错了什么?

func (li *LinkedIn) UploadMedia(URL string, Headers map[string]string, File string) (err error) {
    client := &http.Client{}
    file, err := os.Open(File)
    if err != nil {
        return
    }
    defer file.Close()
    fi, _ := file.Stat()

    request, err := http.NewRequest("PUT", URL, file)
    if err != nil {
        return
    }
    request.Header.Set("Authorization", "Bearer "+li.Token)
    request.Header.Set("X-Restli-Protocol-Version", "2.0.0")
    request.Header.Set("Accept", "*/*")
    if val, ok := Headers["media-type-family"]; ok && val == "STILLIMAGE" {
        request.Header.Set("Content-Type", "text/plain")
    }
    for i, v := range Headers {
        request.Header.Set(i, v)
    }
    request.ContentLength = fi.Size()
    request.TransferEncoding = []string{"identity"}
    response, err := client.Do(request)
    if err != nil {
        return
    }
    defer response.Body.Close()
    if response.StatusCode != 200 && response.StatusCode != 201 {
        log.Println(File)
        log.Println(request)
        for name, values := range response.Header {
            // Loop over all values for the name.
            fmt.Println(name, "-", values)
        }
        dump, _ := httputil.DumpRequestOut(request, false)
        log.Println(string(dump))
        log.Println(request.ContentLength)
        log.Println(response.StatusCode)
        log.Println(response)
        responseBody, _ := ioutil.ReadAll(response.Body)
        err = errors.New(string(responseBody))
    }
    return
}

看到这个问题后添加了Acceptheader:

Content-Type 更改为 application/octet-stream 并将请求方法从 PUT 更改为 POST 有效,即使在他们的文档中另有说明