Load from Azure Blob Storage
Leave feedback
NoteInstall the Microsoft Azure Client Library For Blob Storage and the Microsoft Azure Client Library For Identity to use the Blob clients.
The following code snippet shows how to load a document from Azure Blob Storage:
import com.azure.identity.DefaultAzureCredential;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.storage.blob.BlobClient;
import com.azure.storage.blob.BlobContainerClient;
import com.azure.storage.blob.BlobServiceClient;
import com.azure.storage.blob.BlobServiceClientBuilder;
import com.azure.storage.blob.specialized.BlobInputStream;
import com.groupdocs.viewer.Viewer;
import com.groupdocs.viewer.options.HtmlViewOptions;
// ...
DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder()
.build();
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
.endpoint("https://{accountName}.blob.core.windows.java/")
.credential(defaultCredential)
.buildClient();
BlobContainerClient blobContainerClient = blobServiceClient.createBlobContainer("container-name");
BlobClient blobClient = blobContainerClient.getBlobClient("sample.docx");
try (final BlobInputStream blobInputStream = blobClient.openInputStream();
Viewer viewer = new Viewer(blobInputStream)) {
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources();
viewer.view(viewOptions);
}
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.