Upload thumbnail image to vimeo via api call c#

邮差的信 提交于 2020-01-06 03:24:27

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/34499033/upload-thumbnail-image-to-vimeo-via-api-call-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!