• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

C# unable to upload a transient document

New Here ,
Mar 28, 2017 Mar 28, 2017

Copy link to clipboard

Copied

I am trying to upload a transient document in C# and I have not been able to do so.

MultipartFormDataContent mycontent = new MultipartFormDataContent();

        string encodedFileName = HttpUtility.HtmlEncode("1-Registration Form.pdf");

        HttpContent fileContent = new ByteArrayContent(System.IO.File.ReadAllBytes(ConfigurationManager.AppSettings["PATH_TO_PRIVATE_STORAGE"] + @"documents\1-Registration Form.pdf"));

        mycontent.Add(new StringContent("application/pdf"), "Mime-Type");

        mycontent.Add(new StringContent(encodedFileName), "File-Name");

        fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")

        {

            Name = "File",

            FileName = encodedFileName

        };

            mycontent.Add(fileContent);

        var objGetData = new Models();

        var objClient = new RestClient("https://api.na1.echosign.com:443/api/rest/v5");

        var objRequest = new RestRequest("transientDocuments", Method.POST);

        objRequest.AddFile("file", System.IO.File.ReadAllBytes(ConfigurationManager.AppSettings["PATH_TO_PRIVATE_STORAGE"] + @"documents\1-Registration Form.pdf"), "1-Registration Form.pdf");

        objRequest.AddHeader("Access-Token", "MyAPIKeyHere");

        objRequest.RequestFormat = DataFormat.Json;

        objRequest.AddBody(objGetData);

        IRestResponse objResponse = objClient.Execute(objRequest);

        var content = objResponse.Content;

        JObject jsonLinq = JObject.Parse(content);

I get An error saying Bad request.  Any help would be appreciated, I've been at this for a week now.

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation