This is a MATLAB® interface that connects to the Windows Azure™ Storage Blob (WASB) service. This is a low-level interface, if the higher-level interface as provided in MATLAB supports your requirements it is recommended to use that, see https://www.mathworks.com/help/matlab/import_export/work-with-remote-data.html for more details. This interface also supports Table Storage and Queue Storage.
- Requires MATLAB release R2017a or later
To build a required JAR file:
- Maven™
- JDK 8
- Microsoft® Azure Blob Storage SDK for Java®
Please refer to the documents in the Documentation folder to get started. In particular, the Basic Usage provides an overview of using this interface.
This package is used to enable the use of the Azure Table Storage service with MATLAB. In the Software/MATLAB directory run the startup.m to make the software available in the MATLAB environment.
If this is the first time using the interface, as a one-time operation per session (assuming only one storage account is being used), setup the the Cloud Storage Account. This is done using:
% Create a handle to the storage account
az = azure.storage.CloudStorageAccount;
The storage account will need to be configured to work with the Azure account or the development emulator. By default the UseDevelopmentStorage flag is set to true and so the emulator running on localhost will be used. For details of the development emulator see here: https://docs.microsoft.com/en-us/azure/storage/storage-use-emulator. To use Azure itself, disable this setting as follows:
az.UseDevelopmentStorage = false;
An organization's Azure environment may well to be configured to support only https based access, this is enabled as follows:
az.DefaultEndpointsProtocol = 'https';
The following allows one to specify the credentials for the Azure storage account of choice. The AccountName value is the name of the storage account to access and the AccountKey is the associated Key. In the Azure portal select the Storage account then Settings then AccessKeys and then the Key. Normally the Key1 value is used.
az.AccountName = 'myaccountname'
az.AccountKey = 'SVn445qMEABafld3k225l*****[REDACTED_FOR_SECURITY]****RfIhAQtvYzAQr0328/d030GGw=='
The CloudStorageAccount is now ready to connect. When fully configured this looks like:
az.connect()
az
az =
CloudStorageAccount with properties:
AccountName: 'myaccountname'
AccountKey: 'SVn<MYACCOUNTKEY>0GGw=='
ServiceName: 'blob'
DefaultEndpointsProtocol: 'http'
UseDevelopmentStorage: 0
DevelopmentStorageProxyUri: []
Secondary: 0
URI: 'http://myaccountname.blob.core.windows.net/'
BlobEndpoint: 'http://myaccountname.blob.core.windows.net/'
Note, your storage account key is similar to the root password for the storage account. Always be careful to protect the account key. Avoid distributing it to other users, hard-coding it, or saving it anywhere in plain text that is accessible to others. Regenerate the account key using the Azure portal if you believe it may have been compromised.
With a fully configured connection get a handle to a client that allows uploading and downloading from the blob storage.
azClient = azure.storage.blob.CloudBlobClient(az)
azClient =
CloudBlobClient with properties:
DirectoryDelimiter: '/'
Windows Azure blob storage can now be accessed from within MATLAB. Shown below are a few of the common operations for the Blob Storage service.
To create a container for the configured client one can:
azContainer = azure.storage.blob.CloudBlobContainer(azClient,'testcontainer');
azContainer.createIfNotExists()
Blobs can be content of any nature. To generate some data in MATLAB and save it to newly created container is simple.
sampleData = rand(1000,1000); % Approx 7MB
save SampleData sampleData;
Uploading the data to a previously created container, create a blob handle (merely a reference) and upload.
blob = azContainer.getBlockBlobReference(which('SampleData.mat'));
blob.upload();
This file is now available on the Windows Azure Blob Storage service.
With a fully configured connection get a handle to a client that is required to perform CRUD (Create, Retrieve, Update, Delete) operations on Table storage.
azClient = azure.storage.table.CloudTableClient(az)
azClient =
CloudTableClient with properties:
Parent: [1x1 azure.storage.CloudStorageAccount]
To get a list of tables, call the CloudTableClient.listTables() method to retrieve an list of table names.
tableList = azClient.listTables
tableList =
1x14 CloudTable array with properties:
Parent
Name
With a fully configured connection get a handle to a client that is required to perform CRUD (Create, Retrieve, Update, Delete) operations on queue storage.
queueClient = az.createCloudQueueClient()
queueClient =
CloudQueueClient with no properties.
A queue contains a set of messages. The client can be used to create a queue as follows:
queue = queueClient.getQueueReference('my-queue-name');
tf = queue.createIfNotExists();
As message can be created as shown and must then be added to a queue before it can be retrieved:
% Create a text based message
message = azure.storage.queue.CloudQueueMessage('Hello World');
queue.addMessage(message);
MathWorks Products (http://www.mathworks.com)
- MATLAB (R2017a or later)
- MATLAB Compiler and Compiler SDK (R2017a or later)
- MATLAB Production Server (R2017a or later)
- MATLAB Parallel Server (R2017a or later)
This package is primarily tested on Ubuntu™ 18.04 and Windows™ 10.
The license for the MATLAB Interface for Windows Azure Storage Blob is available in the LICENSE.md file in this GitHub repository. This package uses certain third-party content which is licensed under separate license agreements. See the pom.xml file for third-party software downloaded at build time.
Provide suggestions for additional features or capabilities using the following link:
https://www.mathworks.com/products/reference-architectures/request-new-reference-architectures.html
Email: [email protected]