I'm retrieving files using azure blob storage and the following is the code, pdf is not viewable only showing loading indicator, other files are viewable but not pdf.
protected string DocumentPath { get; set; }
private async Task GetDocumentDetails(string filename)
{
try
{
if (containerClient is null)
return;
IsLoading = true;
if (!string.IsNullOrEmpty(filename))
{
// Get a reference to a blob
BlobClient blobClient = containerClient.GetBlobClient(filename);
if (blobClient is null)
return;
// Download the blob's contents and save it to a file
BlobDownloadInfo downloadInfo = await blobClient.DownloadAsync();
using MemoryStream memoryStream = new MemoryStream();
await downloadInfo.Content.CopyToAsync(memoryStream);
memoryStream.Position = 0;
if(downloadInfo?.ContentType == "application/pdf")
{
DocumentType = "pdf";
DocumentPath = "data:application/pdf;base64," + Convert.ToBase64String(memoryStream.ToArray());
}
else if (downloadInfo?.ContentType == "application/msword")
{
DocumentType = "doc";
WordDocument document = WordDocument.Load(memoryStream, ImportFormatType.Docx);
DocxString = JsonConvert.SerializeObject(document);
document.Dispose();
DocumentEditorModule editor = docContainer.GetDocumentEditor();
await editor.Open(DocxString);
}
else if (downloadInfo?.ContentType == "image/jpeg")
{
DocumentType = "image";
DocumentPath = "data:image/jpeg;base64," + Convert.ToBase64String(memoryStream.ToArray());
}
memoryStream.Dispose();
}
StateHasChanged();
}
using Azure.Storage.Blobs as this is currently recommended by Microsoft, and older nugets (Microsoft.Azure.Storage.Blob)are deprecated.