Click here to Skip to main content
15,312,120 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using Daily Motion API to upload video but unfortunately it is not working it produce error that the request was aborted and the line of code which produce the error is
var responseBytes = client.UploadFile(uploadUrl, fileToUpload);

the code of API is
 public static void Main(MyVideo video)
      {

          var accessToken = GetAccessToken();
          Authorize(accessToken);
          var fileToUpload = video.Path;
          var uploadUrl = GetFileUploadUrl(accessToken);
          var response = GetFileUploadResponse(fileToUpload, accessToken, uploadUrl);
          var uploadedResponse = PublishVideo(response, accessToken);
      }

      private static UploadResponse GetFileUploadResponse(string fileToUpload, string accessToken, string uploadUrl)
      {

          var client = new WebClient();

          client.Headers.Add("Authorization", "OAuth " + accessToken);

          var responseBytes = client.UploadFile(uploadUrl, fileToUpload);

          var responseString = Encoding.UTF8.GetString(responseBytes);

          var response = JsonConvert.DeserializeObject<UploadResponse>(responseString);

          return response;
      }





private static UploadedResponse PublishVideo(UploadResponse uploadResponse, string accessToken)
      {
          MyVideo video = new MyVideo();
          var request = WebRequest.Create("https://api.dailymotion.com/me/videos?url=" + HttpUtility.UrlEncode(uploadResponse.url));
          request.Method = "POST";
          request.ContentType = "application/x-www-form-urlencoded";
          request.Headers.Add("Authorization", "OAuth " + accessToken);

          var requestString = String.Format("title={0}&tags={1}&channel={2}&published={3}",
              HttpUtility.UrlEncode("Some new Title"),
              HttpUtility.UrlEncode("Tags"),
              HttpUtility.UrlEncode("news"),
              HttpUtility.UrlEncode("true"));

          var requestBytes = Encoding.UTF8.GetBytes(requestString);

          var requestStream = request.GetRequestStream();

          requestStream.Write(requestBytes, 0, requestBytes.Length);

          var response = request.GetResponse();

          var responseStream = response.GetResponseStream();
          string responseString;
          using (var reader = new StreamReader(responseStream))
          {
              responseString = reader.ReadToEnd();
          }

          var uploadedResponse = JsonConvert.DeserializeObject<UploadedResponse>(responseString);
          return uploadedResponse;
      }


What I have tried:

i already have tried this
private class MyWebClient : WebClient
     {
         protected override WebRequest GetWebRequest(Uri uri)
         {
             WebRequest w = base.GetWebRequest(uri);
             w.Timeout = 20 * 60 * 1000;
             return w;
         }
     }

and also set the httpexecutiontime() in webconfig but nothing works anyone can help me as i am new in MVC C#
Posted
Updated 12-Feb-20 3:22am
Comments
tyson Hamda 16-Sep-19 2:59am
   
hey bro i got the same error can you please tell me how you solve this error thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900