Convert Word Document to PDF using MemoryStream from Azure Storage with Aspose.Words Cloud SDK for .NET C#

I’m having a problem with streams when using WordsApi.PutConvertDocument

Does this function only work with a FileStream? The stream I’m using is a memory stream, because the file I’m wanting to convert is out in Azure storage, not a filepath. I can see it just fine before I push it into a PutConvertDocumentRequest, and ultimately pass the request into PutConvertDocument. Once I do, the memory stream is nearly blank. The ‘result’ stream is not the file I requested to convert. It’s like it loses the file, because it dwindles down to 789 Bytes.

I then push that up into our Azure Storage and can see just an empty file… not the file I streamed into the request and called the convert on. My code is below… any help would be greatly appreciated. We are a paid customer.

CloudStorageAccount account = null;
CloudBlobContainer cloudBlobContainer = null;
MemoryStream memstream = new MemoryStream();

        if (CloudStorageAccount.TryParse(_settings.Value.AzureStorageKey, out account))
        {
            try
            {
                CloudBlobClient client = account.CreateCloudBlobClient();
                var container = client.GetContainerReference(fileInfo[1]);
                var blob = container.GetBlockBlobReference(fileInfo[2]);
               
                CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileInfo[2]);
                await blockBlob.DownloadToStreamAsync(memstream);

                var format = "pdf";
                WordsApi WordsApi = new WordsApi(_settings.Value.AsposeAPIKey, _settings.Value.AsposeAPISID);
                var request = new PutConvertDocumentRequest(memstream, format);
                var result = WordsApi.PutConvertDocument(request);

                var cont = client.GetContainerReference("converted");
                CloudBlockBlob bl = cont.GetBlockBlobReference("test.pdf");
                await bl.UploadFromStreamAsync(result);

            }
            catch (Exception ex)
            {
                throw;
            }
        }

@bdubose

Thanks for your inquiry. We have tested the scenario and noticed the reported issues. We have logged a ticket WORDSCLOUD-687 in our issue tracking system for further investigation and resolution. We will notify you as soon as it is resolved.

@bdubose,

We have investigated the issue and found that you are reading stream from end so you are getting the issue. Please reset its position to start, before passing it to PutConvertDocumentRequest method, it will resolve the issue.

memstream.Position = 0;
var request = new PutConvertDocumentRequest(memstream, format);
var result = WordsApi.PutConvertDocument(request);

That worked!!! Thank you!!!