Search code examples
c#vimeo-api

C# Vimeo Upload - not working


I'm trying to upload a video to my professional account in Vimeo using Vimeo documantation at : https://developer.vimeo.com/api/upload/videos#upload-your-video

Just to try it I've made a simple C# console app : I can get the upload_ticket.

When I "PUT" the video using WebClient.UploadData the file is sent.

try
        {
            WebClient wc = new WebClient();
            wc.Headers.Clear();
            wc.Headers.Add("Authorization", "bearer xxxxxxxxxxx");
            wc.Headers.Add("type", "streaming");                

            var vimeoTicket = JsonConvert.DeserializeObject<JObject>(wc.UploadString("https://api.vimeo.com/me/videos", "POST", ""));

            var file = File.ReadAllBytes(@"d:\3.mp4");

            wc.Headers.Clear();                

            var result= wc.UploadData(new Uri(vimeoTicket["upload_link_secure"].ToString()), "PUT", file);              

            WebClient wc1 = new WebClient();
            wc1.Headers.Clear();
            wc1.Headers.Add("Content-Range", "bytes */*");

            //This line will get me an execption {"The remote server returned an error: (308) Resume Incomplete."}
            var ff1 = wc1.UploadData(vimeoTicket["upload_link_secure"].ToString(), "PUT", new byte[0]);                
        }
        catch (Exception h)
        {

            throw;
        }

in the API doc it says "If this file exists, this will return a response with a HTTP 308 status code and a Range header with the number of bytes on the server."

So why I get an exception without and I dont get any response as in the doc??

Thank you


Solution

  • For some reason the WebClient handle response 308 as an error, for now I've managed to put the code I need into the exception block - until I'll find a way to convince WebClinet 308 is not an enemy....