Load document from Azure Blob Storage
Following example demonstrates how to render document from Azure Blob Storage.
String blobName = "sample.docx";
try (Viewer viewer = new Viewer(downloadFile(blobName))) {
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources();
viewer.view(viewOptions);
}
public InputStream downloadFile(String blobName) {
CloudBlobContainer container = getContainer();
CloudBlob blob = container.getBlobReference(blobName);
ByteArrayOutputStream memoryStream = new ByteArrayOutputStream();
blob.downloadToStream(memoryStream);
return new ByteArrayInputStream(memoryStream.toByteArray());
}
private CloudBlobContainer getContainer() {
String accountName = "***";
String accountKey = "***";
String endpoint = "https://{accountName}.blob.core.windows.java/";
String containerName = "***";
StorageCredentials storageCredentials = new StorageCredentials(accountName, accountKey);
CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(storageCredentials, new URI(endpoint), null, null, null);
CloudBlobClient cloudBlobClient = cloudStorageAccount.createCloudBlobClient();
CloudBlobContainer container = cloudBlobClient.getContainerReference(containerName);
container.createIfNotExists();
return container;
}
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples:
- GroupDocs.Viewer for Java examples, plugins, and showcase
- Document Viewer for .NET App WebForms UI Modern Example
- Document Viewer for Java App Dropwizard UI Modern Example
- Document Viewer for Java Spring UI Example
- GroupDocs.Viewer for .NET samples, plugins and showcase
- Document Viewer for .NET MVC UI Example
Free Online App
Along with full-featured Java library we provide simple but powerful free Apps. You are welcome to view Word, PDF, Excel, PowerPoint documents with free to use online GroupDocs Viewer App.