1

i am using daily motion API for uploading videos from my application but when try to upload more than 2 MB sized video i get this error "The request was aborted: The request was canceled." and this error invoked by this line of code var responseBytes = client.UploadFile(uploadUrl, fileToUpload); and this is my code which i am using to upload video

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

public class UploadResponse
{
    public string format { get; set; }
    public string acodec { get; set; }
    public string vcodec { get; set; }
    public int duration { get; set; }
    public int bitrate { get; set; }
    public string dimension { get; set; }
    public string name { get; set; }
    public int size { get; set; }
    public string url { get; set; }
    public string hash { get; set; }
    public string seal { get; set; }

    public override string ToString()
    {
        var flags = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.FlattenHierarchy;
        System.Reflection.PropertyInfo[] infos = this.GetType().GetProperties(flags);

        StringBuilder sb = new StringBuilder();

        string typeName = this.GetType().Name;
        sb.AppendLine(typeName);
        sb.AppendLine(string.Empty.PadRight(typeName.Length + 5, '='));

        foreach (var info in infos)
        {
            object value = info.GetValue(this, null);
            sb.AppendFormat("{0}: {1}{2}", info.Name, value != null ? value : "null", Environment.NewLine);
        }

        return sb.ToString();
    }
}

private static UploadResponse GetFileUploadResponse(string fileToUpload, string accessToken, string uploadUrl)
{
    // ServicePointManager.DefaultConnectionLimit = 900000;
    //HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(uploadUrl);
    //wr.KeepAlive = false;
    //wr.Timeout = System.Threading.Timeout.Infinite;
    //wr.ProtocolVersion = HttpVersion.Version10;  

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

and i have already tried al the possible solutionsu provided on Stackoverflow earlier also done with http execution time and we client time out but not working please someone help me

Shelby115
  • 2,816
  • 3
  • 36
  • 52
Arslan Afzal
  • 95
  • 2
  • 13

0 Answers0