通过API调用vimeo上传缩略图图像c# [英] Upload thumbnail image to vimeo via api call c#

查看:249
本文介绍了通过API调用vimeo上传缩略图图像c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置通过vimeo api完成的拉式视频上传的缩略图。我正在开发一个C#的Windows服务,请注意,这里没有官方库。目前我使用这个库。我可以通过下面的视频文件成功上传视频,但是,当我尝试上传图像作为视频的缩略图时,我遇到了问题。根据 vimeo picutre上传文档,在步骤2中,我需要上传我的缩略图通过PUT请求。它说,我需要做到以下几点:

  PUT https://i.cloud.vimeo.com/video/ 518016424 
....你的文件在主体中的二进制数据....

我无法弄清楚如何做到这一点。我可以通过使用

  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]
);
字符串temporary_video_dir = ConfigurationManager.AppSettings [TEMP_VIDEO_URL];
词典< 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(在测试文件夹中成功上传视频,返回视频的Vimeo ID:+ 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);


I am trying to set the thumbnail for a pull video upload done through the vimeo api. I am developing this for a c# windows service and please note that there are no official libraries for this. For the moment I use 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, in step 2, i need to upload my thumbnail image via a PUT request. It says, that I need to do the following:

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

I can't figure out how to do this. I can get the binary data of the image by using

byte[] byte_array_of_image = File.ReadAllBytes(file);

but how can I send this data to the api and get a response (with or without using the library)? If it would help, here is my code to upload the video and thumbnail done so far.

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];

Please help! Stuck for hours now.

解决方案

WebClient has a method called UploadData that fits like a glove. Below there is an example that what you can do.

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);

这篇关于通过API调用vimeo上传缩略图图像c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆