Web Services - Ws - UploadFiles

9/5/2019


We'd suggesting uploading one file at a time, unless you wish multiple files to be treated as if they all belonged to the same document e.g. two separate jpg images from photos of a two page document. 

Sample C# code to use the web service:       
private const string myUserName = "myemail@mydomain.com";
private const string myPassword = "password";
string myUrlPrefix = "https://documentvacuum.com/";

public async Task<ActionResult> UploadFiles()
{
    int householdId = 0; //needs to be a valid householdId
    string version = "0";
    string entityId="abcd"; //dummy entry or optional primary key of user's source document

    int daysToExpiration=60; //an integer >= 1

    int pdem=1; //1=pdf (assumed to have embedded text)
    //2=pdf treated as an image file, 3=non pdf file

   //Use exactly one of the three following lines
    string uploadMode = "normal";
    //string uploadMode = "anonymousAuth";
    //string uploadMode = "reference";

   Boolean tableExtraction = false; //Used in anonymous mode.
   Boolean seqRowExtraction = false; //Used in normal mode.
   Boolean mappingSelected = false; //Used in reference mode
   Boolean pdrcWrong = false;  //Used in normal and reference mode

    //The valid combinations of uploadMode, tableExtraction, seqRowExtraction
    //pdrcWrong and mappingSelected are:
    //uploadMode == "normal" && seqRowExtraction == false && pdrcWrong == false
    //uploadMode == "normal" && seqRowExtraction == false && pdrcWrong == true
    //uploadMode == "normal" && seqRowExtraction == true && pdrcWrong == false
    //uploadMode == "normal" && seqRowExtraction == true && pdrcWrong == true
    //uploadMode == "anonymousAuth" && tableExtraction == false
    //uploadMode == "anonymousAuth" && tableExtraction == true
    //uploadMode == "reference" && mappingSelected == false && pdrcWrong == false
    //uploadMode == "reference" && mappingSelected == false && pdrcWrong == true
    //uploadMode == "reference" && mappingSelected == false && pdrcWrong == false
    //uploadMode == "reference" && mappingSelected == true && pdrcWrong == true
     int maxStatusId=21;

    HttpClient client = new HttpClient();
    MultipartFormDataContent content = new MultipartFormDataContent();

    var buffer = System.Text.Encoding.ASCII.GetBytes(myUserName + ":" + myPassword);
    var authHeader = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic",
        Convert.ToBase64String(buffer));
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Authorization = authHeader;
    client.BaseAddress = new Uri(myUrlPrefix);

    //Two things to note on the demo, need to have actual image files in the code below and the file
    //name that is created when the code is run should be read from the list of pDocDetails that comes
    //back upon successful completion, the server code removes certain characters in the file name,
    //limits the length, standardizes file extensions etc.


    var fileContent1 =
        new ByteArrayContent(System.IO.File.ReadAllBytes(@"C:\temp\MyFirstDocument.pdf"));
    fileContent1.Headers.ContentDisposition =
        new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
        {
            FileName = "MyFirstDocument.pdf"
        };
    content.Add(fileContent1);

    var fileContent2 =
        new ByteArrayContent(System.IO.File.ReadAllBytes(@"C:\temp\MySecondDocument.pdf"));
    fileContent2.Headers.ContentDisposition =
        new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
        {
            FileName = "MySecondDocument.pdf"
        };
    content.Add(fileContent2);
               
    string myUrlSuffix =
        "api/MyDocNcApi/UploadFiles?version=" + version +
        "&householdId=" + householdId +
        "&daysToExpiration=" + daysToExpiration +
        "&pdem=" + pdem +
        "&uploadMode=" + uploadMode +
        "&tableExtraction=" + tableExtraction +
        "&seqRowExtraction=" + seqRowExtraction +
        "&mappingSelected=" + mappingSelected +
        "&pdrcWrong=" + pdrcWrong +
        "&entityId=" + entityId +
        "&maxStatusId=" + maxStatusId;
           
    try
    {
        var task = await client.PostAsync(myUrlSuffix, content);
        HttpStatusCode statusCode = task.StatusCode;

        var output = task.Content.ReadAsStringAsync().Result;
        if (statusCode == System.Net.HttpStatusCode.OK)
        {
            string outcome = "Success";
            List<PDocDetailNc> pddNcList = JsonConvert.DeserializeObject<List<PDocDetailNc>>(output);
        }
        else if (statusCode == HttpStatusCode.Unauthorized)
        {
            string outcome = "Bad login credentials or insufficient account permissions";
        }
        else if (statusCode == HttpStatusCode.NotImplemented)
        {
            string outcome = "pdem, daysToExpiration or the combination of uploadMode, tableExtraction, " +
               "sequentialRowExtraction, mappingSelected and pdrcWrong not set properly";
        }
        else if (statusCode == HttpStatusCode.NoContent)
        {
           string outcome = "An empty file, one with an invalid name or file extension " +
                "or one too large to process";
        }
       else if (statusCode == HttpStatusCode.BadRequest)
       {
           string outcome = "Nc class sent has something wrong with it.";
           outcome = task.ReasonPhrase;
       }
       else if (statusCode == HttpStatusCode.InternalServerError)
       {
           string outcome = "Something else went wrong";
       }
    }
    catch (Exception e)
    {

    }
    return RedirectToAction("Index");
}


Other articles:
Billing - DocVacBasic & DocVacGold
Web Services - Ws - GetPDocPageClassificationNc
Web Services - Usage Charges
Postman
Web Services - Class - PDocDetailNc
Web Services - Class - PDocPageNc
Web Services - Class - PDocRowClassificationNc
Web Services - Class - PDocRowXmlNc
Web Services - Class - PdrxDataTypeNc
Web Services - Class - PdrxstnMappingNc
more