send byte array using Platform .NET API
Currently using docuware platform is not possible to send files without saving them to disk, it would be grait to send files using byte array or streams.
Docuware Platform
-
James Heim commented
Uploading via stream really is something that should be implemented in order to develop software that works programmatically. Relying on FileInfo for all uploads adds unnecessary steps and storage management.
-
Anonymous commented
you can do it with this extension class.
I hope it helps someone
Best regardspublic static class DWExtensions{
private static async Task<DeserializedHttpResponse<T>> PostAsync<T>(ServiceConnection service, string uri, HttpContent content) where T : new(){
HttpResponseMessage message = await service.HttpClient.PostAsync(uri, content);DeserializedHttpResponse<T> dresp;
if (message.IsSuccessStatusCode)
{
T newdoc = DocuWare.Services.Http.Client.XmlSerializerRepository.ParseFromXmlString<T>(await message.Content.ReadAsStringAsync());
dresp = new DocuWare.Services.Http.DeserializedHttpResponse<T>(message, newdoc);
}
else
{
dresp = new DocuWare.Services.Http.DeserializedHttpResponse<T>(message, default(T));
}return dresp;
}
public static async Task<DeserializedHttpResponse<Document>> UploadDocumentAsync(this ServiceConnection service, string Cabinet, HttpContent content, bool? processTextshot = null, bool? imageProcessing = null, string redirect = null, string storeDialogId = null, bool? checkFileNameForCheckinInfo = null)
{
string uri = string.Format("FileCabinets/{0}/Documents?processTextshot={1}&imageProcessing={2}&redirect={3}&storeDialogId={4}&checkFileNameForCheckinInfo={5}", Cabinet, processTextshot, imageProcessing, redirect, storeDialogId, checkFileNameForCheckinInfo);
return await PostAsync<Document>(service, uri, content);
}
}public void CallExample(){
Document newdoc = new Document();
byte[] ByteData = new byte[100];
//fill index data
newdoc.Fields = new List<DocumentIndexField>();
newdoc.Fields.Add(new DocumentIndexField() { FieldName = "FIELD", Item = "string value", ItemElementName = ItemChoiceType.String });
MultipartFormDataContent content = new MultipartFormDataContent();
//add xml params
var parameters = DocuWare.Services.Http.Client.ContentHelper.CreateXmlContent<Document>(newdoc);
content.Add(parameters, "params", "params.xml");var citem = new ByteArrayContent(ByteData));
citem.Headers.ContentType = new MediaTypeHeaderValue(GetFileMIMEType(docDescription.files[i].FileName));
content.Add(citem, "file", docDescription.files[i].FileName);
//Store document with index data
var newdoc = await client.UploadDocumentAsync(Cabinet, content);
}