Provide the Blob SAS token and Storage URI

To make the code more generic, the two properties can be configured using the OSGi configuration as shown below. The aemformstutorial is the name of the storage account, formsubmissions is the container in which the data will be stored.
Please make sure you have / at the end of the storage uri and the SAS token starts with?
osgi-configuration

Create PUT request

The next step is to create a PUT request to store the submitted form data in Azure Storage. Every form submission needs to be identified by a unique BLOB ID. The unique BLOB ID is typically created in your code and inserted in the url of the PUT request.
The following is the partial URL of the PUT request. The aemformstutorial is the name of the storage account, formsubmissions is the container in which the data will be stored with unique BLOB ID. The rest of the url will be remain the same.
https://aemformstutorial.blob.core.windows.net/formsubmissions/blobid/sastoken
The following is function written to store the submitted form data in Azure Storage using a PUT request. Notice the use of container name and the uuid in the url. You can create an OSGi service or a sling servlet using the sample code listed below and store the form submissions in Azure Storage.

 public String saveFormDatainAzure(String formData) {
    log.debug("in SaveFormData!!!!!" + formData);
    String sasToken = azurePortalConfigurationService.getSASToken();
    String storageURI = azurePortalConfigurationService.getStorageURI();
    log.debug("The SAS Token is " + sasToken);
    log.debug("The Storage URL is " + storageURI);
    org.apache.http.impl.client.CloseableHttpClient httpClient = HttpClientBuilder.create().build();
    UUID uuid = UUID.randomUUID();
    String putRequestURL = storageURI + uuid.toString();
    putRequestURL = putRequestURL + sasToken;
    HttpPut httpPut = new HttpPut(putRequestURL);
    httpPut.addHeader("x-ms-blob-type", "BlockBlob");
    httpPut.addHeader("Content-Type", "text/plain");

    try {
        httpPut.setEntity(new StringEntity(formData));

        CloseableHttpResponse response = httpClient.execute(httpPut);
        log.debug("Response code " + response.getStatusLine().getStatusCode());
        if (response.getStatusLine().getStatusCode() == 201) {
            return uuid.toString();
        }
    } catch (IOException e) {
        log.error("Error: " + e.getMessage());
        throw new RuntimeException(e);
    }
    return null;

}

Verify stored data in the container

form-data-in-container

Test the solution

Previous pageSend e-mails with SendGrid
Next pagePopulate form with Azure Blob

Experience Manager