通过 api 调用 c# 将缩略图上传到 vimeo

Upload thumbnail image to vimeo via api call c#

我正在尝试为通过 vimeo api 完成的拉取视频上传设置缩略图。我正在为 c# windows 服务开发这个,请注意没有官方库。目前我使用 this library. I am able to successfully upload the video by following the vimeo documentation, however, when I try to upload an image to be the thumbnail of a video I get an issue. According to the vimeo picutre upload documentation,在第 2 步中,我需要通过 PUT 请求上传我的缩略图。它说,我需要执行以下操作:

PUT https://i.cloud.vimeo.com/video/518016424
.... binary data of your file in the body ....

我不知道该怎么做。我可以使用

获取图像的二进制数据
byte[] byte_array_of_image = File.ReadAllBytes(file);

但是我如何将这些数据发送到 api 并获得响应(使用或不使用库)?如果有帮助,这是我上传到目前为止完成的视频和缩略图的代码。

var vc = VimeoClient.ReAuthorize(
            accessToken: ConfigurationManager.AppSettings["ACCESS_TOKEN"],
            cid: ConfigurationManager.AppSettings["API_KEY"],
            secret: ConfigurationManager.AppSettings["API_SECRET"]
            );
            string temporary_video_dir = ConfigurationManager.AppSettings["TEMP_VIDEO_URL"];
            Dictionary<string,string> automatic_pull_parameters = new Dictionary<string, string>();
            automatic_pull_parameters.Add("type", "pull");
            automatic_pull_parameters.Add("link", temporary_video_dir);
var video_upload_request = vc.Request("/me/videos", automatic_pull_parameters, "POST");
                string uploaded_URI = video_upload_request["uri"].ToString();
                string video_id = uploaded_URI.Split('/')[2];
                Library.WriteErrorLog("Succesfully uploaded Video in test folder. Returned Vimeo ID for video: "+ video_id);
 var picture_resource_request = vc.Request("/videos/" + video_id + "/pictures", null, "POST");
                string picture_resource_link = picture_resource_request["uri"].ToString();
                //Library.WriteErrorLog("uri: " + picture_resource_link);

                byte[] binary_image_data = File.ReadAllBytes("http://testclient.xitech.com.au/Videos/Images/Closing_2051.jpg");
                string thumbnail_upload_link = picture_resource_link.Split('/')[4];

请帮忙!卡了几个小时了。

WebClient 有一个叫做 UploadData 的方法,非常合身。下面是您可以做什么的示例。

WebClient wb = new WebClient();
wb.Headers.Add("Authorization","Bearer" +AccessToken);
var file =  wb.DownloadData(new Uri("http://testclient.xitech.com.au/Videos/Images/Closing_2051.jpg"));
var asByteArrayContent = wb.UploadData(new Uri(picture_resource_request ), "PUT", file);
var asStringContent = Encoding.UTF8.GetString(asByteArrayContent);

参考 post:-

答案没有被赞成,但可以尝试在我的情况下效果很好。 请参阅下面的代码:-

     public ActionResult UploadChapterVideoVimeo(HttpPostedFileBase file, string productID = "")
{
    if (file != null){      
                      var authCheck = Task.Run(async () => await vimeoClient.GetAccountInformationAsync()).Result;
                if (authCheck.Name != null)
                {
                    
                    BinaryContent binaryContent = new BinaryContent(file.InputStream, file.ContentType);
                    int chunkSize = 0;
                    int contenetLength = file.ContentLength;
                    int temp1 = contenetLength / 1024;
                    if (temp1 > 1)
                    {
                        chunkSize = temp1 / 1024;
                        chunkSize = chunkSize * 1048576;
                    }
                    else
                    { chunkSize = chunkSize * 1048576; }
                    binaryContent.OriginalFileName = file.FileName;
                    var d = Task.Run(async () => await vimeoClient.UploadEntireFileAsync(binaryContent, chunkSize, null)).Result;
                    vmodel.chapter_vimeo_url = "VIMEO-" + d.ClipUri;
                }

                return RedirectToAction("ProductBuilder", "Products", new { productId = EncryptedProductID, message = "Successfully Uploaded video", type = 1 });
            }
        }
        catch (Exception exc)
        {
            return RedirectToAction("ProductBuilder", "Products", new { productId = EncryptedProductID, message = "Failed to Uploaded video " + exc.Message, type = 0 });
        }
    }
    return null;        }