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;
}
}