Load file from Azure blob storage
Leave feedback
The following code snippet shows how to convert a file from Azure Blob Storage. It uses the Azure.Storage.Blobs NuGet package:
public static void Run()
{
string blobName = "sample.docx";
string outputFile = Path.Combine(@"c:\output", "converted.pdf");
using (Converter converter = new Converter(() => DownloadFile(blobName)))
{
PdfConvertOptions options = new PdfConvertOptions();
converter.Convert(outputFile, options);
}
}
public static Stream DownloadFile(string blobName)
{
BlobContainerClient container = GetContainer();
BlobClient blob = container.GetBlobClient(blobName);
MemoryStream memoryStream = new MemoryStream();
blob.DownloadTo(memoryStream);
memoryStream.Position = 0;
return memoryStream;
}
private static BlobContainerClient GetContainer()
{
string accountName = "***";
string accountKey = "***";
string containerName = "***";
Uri containerUri = new Uri($"https://{accountName}.blob.core.windows.net/{containerName}");
StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey);
return new BlobContainerClient(containerUri, credential);
}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.