'Upload DocuWare File Using Byte Array

How do you upload a file to DocuWare, via the .NET API, using a byte array? Currently it appears that you can only use a FileInfo object which requires the file to be on disk. https://developer.docuware.com/sdk/platform-fox/html/57da87ed-111c-4f78-96e9-75d3b9462ce9.htm



Solution 1:[1]

This can be achieved by building the request using the DocuWare .NET API and then calling the DocuWare REST API. I'm sure this example can be improved upon greatly but it's a good starting point.

public void UploadFileToCabinet(byte[] fileToUpload, string contentType, string fileName, string documentType)
    {
        // Authentication
        ServiceConnection docuWareConn = ServiceConnection.CreateTrusted("[docuWareUri]", "[userToImpersonate]", "[trustedUsername]", "[trustedUserPassword]", "[organizationName]", DWProductTypes.PlatformService);
        Organization org = docuWareConn.Organizations.FirstOrDefault();
            
        // Create object that will be sent in the POST body.           
        var content = new MultipartFormDataContent();

        // Add the byte array.
        var citem = new ByteArrayContent(fileToUpload);

        // Include any desired index parameters.
        Document newdoc = new Document();
        newdoc.Fields = new List<DocumentIndexField>();
        newdoc.Fields.Add(DocumentIndexField.Create("DOCUMENT_TYPE", documentType));

        var parameters = DocuWare.Services.Http.Client.ContentHelper.CreateXmlContent(newdoc);
        content.Add(parameters, "params", "params.xml");

        citem.Headers.ContentType = new MediaTypeHeaderValue(contentType);
        content.Add(citem, "file", fileName);

        // Send the request to the DocuWare REST API.
        HttpResponseMessage message = docuWareConn.HttpClient.PostAsync($"[docuWareUri]/FileCabinets/[FileCabinetID]/Documents", content).Result;
       
    } 

Inspired by an anonymous answer to a question on this DocuWare thread. Thanks Anonymous, your answer did help someone and I'm sharing my modified solution on Stack Overflow to hopefully help others. https://docuware.uservoice.com/forums/230573-miscellaneous-english/suggestions/11165103-send-byte-array-using-platform-net-api

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gabe