ColdFusion and Azure Blob

Introduction

Blob or Binary Large OBject include images, text files, videos, or audio. Azure BLOB storage is a persistent data storage in cloud, which you can utilize to store BLOB data.

ColdFusion and Azure Blob

ColdFusion (2018 release) included support for AWS S3 storage service. In ColdFusion (2021 release), we have extended it to provide multi-cloud storage with Azure Blob, so that you can use different storage services for storing and retrieve data based on your requirement.

In ColdFusion, you can use the following operations for Azure storage service.

  • Perform different operations, for example, create, update, delete, or list in a container.
  • Upload and download items from the blob.
  • Apply policies in a container.
  • Copy a blob from one container to another container in the same account.
  • Share permission for container or blob in different user using shared access signature.
Remarque :

On Weblogic 14.1.1.0.0, an Null Pointer Exception occurs when using Azure Blob as storage. For the workaround, see the work-around.

Get started

Install azureblob package

Adobe ColdFusion (2021 release) is modularized, if you are only using the ZIP installer. By default, the package for Azure Blob is not installed. The first step is to install the Blob package in ColdFusion.

Note: If you are using the GUI installer, the packages are pre-installed.

The package for Blob is called azureblob.

To install the package azureblob, use the Package Manager page in the ColdFusion Administrator, or follow the steps below:

  1. Navigate to <CF_HOME>/cfusion/bin.

  2. Enter the command:

    • Windows: cfpm.bat
    • Linux: cfpm.sh
  3. Enter the command, install azureblob.

    Wait for the Azure Blob package to get installed.

For more information, see ColdFusion Package Manager.

Add cloud service credentials and configuration

In ColdFusion (2021 release), there is a method getCloudService() that gives you a handle to create objects for accessing various cloud services.

The syntax of the service handle is as follows:

service=getCloudService(cloudCred,cloudConfig), where:

  • cloudCred: Defines the credentials for the cloud service. It could either be a struct or a string (also known as credential alias).
  • cloudConfig: Defines the cloud service configuration details. It could either be a struct or a string (also known as config alias).

After you've acquired the Azure credentials, you must declare these credentials in one of the following ways. Only then you can use these credentials to create a Blob object, after which you can use the object to make calls to the various Azure Blob methods.

ColdFusion Administrator

Set credentials

In the ColdFusion Administrator, click Data & Services > Cloud Credentials

An alias is a named representation of a cloud service and its configuration details. You can set the config alias through ColdFusion Administrator.

Add cloud credentials
Add cloud credentials

A connection string includes the authorization information required for your application to access data in an Azure Storage account.

For more information, see Configure Azure Storage connection strings.

After entering the details, click Add Credential.

Set configuration options

In the ColdFusion Administrator, click Data & Services > Cloud Configuration

Enter the following details, like configuration Alias, Vendor, and the name of the service.

Add cloud configuration options
Add cloud configuration options

After adding the configuration options, you may need to add a few more options. You can do so in the next screen. The following are a few options that you may need to add:

  • Concurrent Request Count
  • Single block size in bytes
  • Maximum Execution time (ms)
  • Retry policy type
  • Enable logging

For more information, see Cloud configuration options.

CREATE THE AZURE BLOB SERVICE OBJECT

Once you've created the aliases for Blob credential and configuration options, you can create the object by using the getCloudService API, and include the following in your CFM. 

blobObject= getCloudService("blobCred", "blobConf")

Application.cfc

You can specify the Blob credentials and configuration options in Application.cfc. For example,

omponent { 
    this.name ="AzureblobTest" 
    this.serialization.preservecaseforstructkey=true 
    this.enableNullSupport=true 
    void function onApplicationStart(){ 
        application.blobCred = { 
            "vendorName" : "AZURE", 
            "connectionString" : "xxxxxxxxxxx" 
        } 
 
        application.blobConf = { 
            "serviceName" : "AZURE_BLOB" 
        } 
 } 
 
}

CREATE THE AZURE BLOB SERVICE OBJECT

blobObject = getCloudService(application.blobCred, application.blobConf) 

On CFM page

On a CFM page, you can specify the Blob credentials and configuration options in one of the four methods, specified below:

Credential alias and configuration alias

After you've created the aliases for Azure Blob credential and configuration options, you can use these aliases in the getCloudService handle as shown below:

<cfscript> 
  // define the credential and the configuration aliases in the ColdFusion Admin 
  blobObject=getCloudService("blobCred","blobConf") 
  // code below. 
  ........... 
</cfscript>

Credential Alias and Struct for configuration options

<cfscript> 
    blobCred = { 
        "vendorName" : "AZURE", 
        "connectionString" : "xxxxxx" 
    } 
    blobConf = { 
        "serviceName" : "AZURE_BLOB", 
        "options" : { 
            "absorbConditionalErrorsOnRetry" : true/false, 
            "concurrentRequestCount" : 5, 
            "useTransactionalContentMD5" : true/false, 
            "storeBlobContentMD5" : true/false, 
            "disableContentMD5Validation": true/fasle, 
            "singleBlobPutThresholdInBytes" : 12345, 
            "skipEtagLocking" : true/false, 
            "retryPolicyFactory": { 
                "retryPolicyType" : "EXPONENTIAL" | "LINEAR" | "NONE", 
                "deltaBackoffIntervalInMs" : 12, 
                "maxAttempts" : 3, 
                "resolvedMinBackoff" : 1 
            }, 
            "locationMode" : "PRIMARY_ONLY" | "PRIMARY_THEN_SECONDARY" | "SECONDARY_ONLY" | "SECONDARY_THEN_PRIMARY", 
            "maximumExecutionTimeInMs" : 2, 
            "timeoutIntervalInMs" : 1 
        } 
    } 
</cfscript>

Configuration alias and struct for credentials

<cfscript> 
    // Using config alias and struct for service credentials 
    // blob credentials 
    blobCreds={ 
      "vendorName" : "AZURE", 
        "connectionString" : "xxxxxx" 
    } 
    blobObject= getCloudService(blobCreds, "blobConf") 
    // code below 
    ..................................... 
</cfscript>

Structs for both credential and configuration options

<cfscript> 
  // Using Structs for both cloud credential and config 
  blobCred = { 
        "vendorName" : "AZURE", 
        "connectionString" : "xxxxxx" 
    } 
    blobConf = { 
        "serviceName" : "AZURE_BLOB", 
        "options" : { 
            "absorbConditionalErrorsOnRetry" : true/false, 
            "concurrentRequestCount" : 5, 
            "useTransactionalContentMD5" : true/false, 
            "storeBlobContentMD5" : true/false, 
            "disableContentMD5Validation": true/fasle, 
            "singleBlobPutThresholdInBytes" : 12345, 
            "skipEtagLocking" : true/false, 
            "retryPolicyFactory": { 
                "retryPolicyType" : "EXPONENTIAL" | "LINEAR" | "NONE", 
                "deltaBackoffIntervalInMs" : 12, 
                "maxAttempts" : 3, 
                "resolvedMinBackoff" : 1 
            }, 
            "locationMode" : "PRIMARY_ONLY" | "PRIMARY_THEN_SECONDARY" | "SECONDARY_ONLY" | "SECONDARY_THEN_PRIMARY", 
            "maximumExecutionTimeInMs" : 2, 
            "timeoutIntervalInMs" : 1 
        } 
    } 
  blob = getCloudService(blobCred, blobConf ) 
   
  // code below 
  ................................................................... 
</cfscript>

Admin API

You can also add SQS credentials and configuration options by using the Admin APIs. The methods to add credentials and configuration are available in cloud.cfc.

The examples below demonstrate the usage of the methods addCredential(struct credential) and addServiceConfig(struct config).

Add credentials

<cfscript> 
  // Create an object of administrator component and call the login method 
  adminObj = createObject("component","cfide.adminapi.administrator") 
  adminObj.login("admin") 
   
  // Create an object of cloud component 
  cloudObj = createObject("component","cfide.adminapi.cloud") 
   
  // define credentials struct 
  credentialStruct={ 
        "vendorName" : "AZURE", 
        "connectionString" : "xxxxxx" 
  } 
   
  // add credential credentialStruct 
  try{ 
    cloudObj.addCredential(credentialStruct) 
    writeOutput("Credentials added successfully") 
  } 
  catch(any e){ 
      writeDump(e) 
  } 
</cfscript>

Add configuration

<cfscript> 
  // Create an object of administrator component and call the login method 
  adminObj = createObject("component","cfide.adminapi.administrator") 
  adminObj.login("admin") 
   
  // Create an object of cloud component 
  cloudObj = createObject("component","cfide.adminapi.cloud") 
   
  // define configuration struct 
  configStruct={ 
      ""serviceName" : "AZURE_BLOB", 
        "options" : { 
            "absorbConditionalErrorsOnRetry" : true/false, 
            "concurrentRequestCount" : 5, 
            "useTransactionalContentMD5" : true/false, 
            "storeBlobContentMD5" : true/false, 
            "disableContentMD5Validation": true/fasle, 
            "singleBlobPutThresholdInBytes" : 12345, 
            "skipEtagLocking" : true/false, 
            "retryPolicyFactory": { 
                "retryPolicyType" : "EXPONENTIAL" | "LINEAR" | "NONE", 
                "deltaBackoffIntervalInMs" : 12, 
                "maxAttempts" : 3, 
                "resolvedMinBackoff" : 1 
            }, 
            "locationMode" : "PRIMARY_ONLY" | "PRIMARY_THEN_SECONDARY" | "SECONDARY_ONLY" | "SECONDARY_THEN_PRIMARY", 
            "maximumExecutionTimeInMs" : 2, 
            "timeoutIntervalInMs" : 1 
        } 
  } 
   
  // add config configStruct 
  try{ 
    cloudObj.addServiceConfig(configStruct) 
    writeOutput("Configuration service added successfully") 
  } 
  catch(any e){ 
    writeDump(e) 
  } 
</cfscript>

CFSetup

You can also set up SQS credential and configuration via the CFSetup configuration utility.

Add cloud credential

  • add cloudcredential credentialAlias=blobCred accesskeyid=<access> secretaccesskey=<secret> region=ap-southeast-1 vendorname=AWS

Set credential

  • set cloudcredential snscred secretaccesskey=awssecret

Add cloud configuration

  • add cloudconfiguration serviceName=S3 alias=s3Config

Set configuration

  • set cloudconfiguration conf1 alias=conf2

Create root

Create the root object. If the root doesn't exist, the root gets created.

  • Amazon S3- Yes
  • Azure- Yes
  • Multi-cloud- Yes

Syntax

root(rootName, createIfNotExists)

Parameters

Parameter

Description

Required

rootName

The name of the root to be created.

Yes

createIfNotExists

True or False. If the root doesn't exist, it gets created.

No

Example

<cfscript> 
  storageService = getCloudService(application.blobCred, application.blobConf) 
  // create a root 
  try{ 
    storageService.root("root014","false") // createIfNotExists=FALSE 
    writeOutput("Root created successfully") 
    } 
  catch(any e){ 
    writeOutput("Unable to create root") 
  } 
</cfscript>

Create root- additional parameters

Create the root object with additional parameters.

  • Amazon S3- Yes
  • Azure- Yes
  • Multi-cloud- Yes

Syntax

createRoot(parameterStruct)

Parameters

Parameter

Description

Required

containerName

The name of the root to be created.

Yes

publicAccesstype

The parameter publicAccessType defines the level at which the access will be granted. This parameter can accept one of the three values:

  • BLOB: Specifies blob-level public access. Clients can read the content and metadata of blobs within this container but cannot read container metadata or list the blobs within the container.
  • CONTAINER: Specifies container-level public access. Clients can read blob content and metadata and container metadata and can list the blobs within the container.
  • OFF: Specifies no public access. Only the account owner can access resources in this container.

No

Example

<cfscript> 
    storageService = getCloudService(application.blobCred, application.blobConf) 
    // create a root object 
    createRequest= { 
        "containerName" : "root111", 
        "publicAccessType" :"BLOB" 
    } 
    try{ 
        storageService.createcontainer(createRequest) 
        writeOutput("Root created successfully") 
    } 
    catch(any e){ 
        writeDump(e) 
    } 
</cfscript>

List all blobs

 Get the list of root objects in the storage account.

  • Amazon S3- Yes
  • Azure- Yes
  • Multi-cloud- Yes

Syntax

listAll(parameterStruct)

Parameters

Parameter

Description

Required

prefix

Returns only those blobs whose names begin with the specified prefix.

No

isFlatList

True or False. 

No

listingDetails

Specify one or more values to include in the response:

  • SNAPSHOTS: Specifies that snapshots must be included in the response.
  • METADATA: Specifies that blob metadata is included in the response.
  • COPY: Specifies that metadata related to a blob copy operation must be included in the response.

No

Example

<cfscript> 
    storageService = getCloudService(application.blobCred, application.blobConf) 
    // list all blobs 
    blobList=storageService.listAll() 
    writeDump(blobList) 
</cfscript>

Delete a blob

Delete a blob and its snaphot.

  • Amazon S3- Yes
  • Azure- Yes
  • Multi-cloud- Yes

Syntax

delete(parameterStruct)

Parameters

Parameter

Description

Required

key

The name of the blob to delete.

Yes

deleteSnapshotsOption

Specify the blob snapshot to delete. Valid values are:

  • DELETE_SNAPSHOTS_ONLY
  • INCLUDE_SNAPSHOTS
  • NONE

No

Example

<cfscript> 
  storageService = getCloudService(application.blobCred, application.blobConf) 
  // create a root 
  try{ 
    storageService.root("root014","false") // createIfNotExists=FALSE 
    writeOutput("Root created successfully") 
    } 
  catch(any e){ 
    writeOutput("Unable to create root") 
  } 
  rootArray=storageService.listAll() 
  writedump(rootArray[1]) 
 
  // delete the root 
  try{ 
    storageService.delete(rootArray[1].name) 
    writeOutput("Root deleted successfully") 
  } 
  catch(any e){ 
    writeOutput("Unable to delete root") 
  } 
</cfscript> 

Upload file in container

You can upload a file to a container.

For more information, see Upload file to a blob.

  • Amazon S3- Yes
  • Azure- Yes
  • Multi-cloud- Yes

Syntax

uploadFile(parameterStruct)

Parameters

Parameter

Description

Required

key

The name of the file.

Yes

srcFile

The path of the file to be uploaded.

Yes

accessCondition

An AccessCondition object that represents the condition that must be met in order for the request to proceed. Valid values are:

  • leaseID
  • ifMatchETag
  • ifNoneMatchETag
  • ifModifiedSinceDate
  • ifUnmodifiedSinceDate
  • ifSequenceNumberLessThanOrEqual
  • ifSequenceNumberLessThan
  • ifSequenceNumberEqual
  • ifMaxSizeLessThanOrEqual
  • ifAppendPositionEqual

No

context

Represents the context of the current operation.

No

options

Specifies additional options for the request. If null, default options are applied to the request.

No

Example

<cfscript> 
  storageService = getCloudService(application.blobCred, application.blobConf) 
  // create container struct 
  createRequest= { 
      "containerName" : "container3", 
      "publicAccessType" :"BLOB" 
  } 
  rootObj=storageService.createcontainer(createRequest) 
   
  // An accessCondition object that represents the condition that must be met in order for the request to proceed. 
  uploadStruct = { 
    "blobName" : "blob003", 
    "srcFile" : "#ExpandPath('./')#/file.txt" 
  } 
 
 
  try { 
    uploadResponse=rootObj.uploadFile(uploadStruct) 
    writeOutput("File uploaded successfully") 
    writeDump(uploadResponse) 
  } 
  catch(any e){ 
    writeDump(e) 
  } 
 
</cfscript> 

Download file from container

Download a file from a container.

  • Amazon S3- Yes
  • Azure- Yes
  • Multi-cloud- Yes

Syntax

downloadToFile(parameterStruct)

Parameters

Parameter

Description

Required

destinationFile

The path where you want to download the file.

Yes

key

The key associated with the container.

Yes

Example

<cfscript> 
  storageService = getCloudService(application.blobCred, application.blobConf) 
    // upload a File 
    uploadStruct = { 
      "key" : "key001", 
      "srcFile" : "#ExpandPath('./')#/file.txt" 
    } 
    try { 
      rootObj=storageService.root("root015","true") // createIfNotExists=FALSE 
      uploadResponse=rootObj.uploadFile(uploadStruct) 
      writeOutput("File uploaded successfully") 
      // writeDump(uploadResponse) 
    } 
    catch(any e){ 
      writeOutput("File upload failed") 
    } 
    // download the file 
    downloadStruct={ 
      "key": "key001", 
      "destinationFile": "file.txt" 
    } 
    try{ 
      downloadResponse=rootObj.downloadToFile(downloadStruct) 
      writeOutput("File downloaded successfully") 
    } 
    catch (any e){ 
      writedump(e) 
    } 
</cfscript> 

Copy blob

Copy a blob to another blob.

  • Amazon S3- Yes
  • Azure- Yes
  • Multi-cloud- Yes

Syntax

copy(paramerStruct)

Parameters

Parameter

Description

Required

source

The source blob.

Yes

sourceVersion

The version with the blob was uploaded.

No

sourceAccessCondition

Represents a set of access conditions to be used for operations against the storage services.

No

storageClass

Valid values are:

  • HOT
  • COOL
  • ARCHIVE

No

key

The key associated with the blob.

Yes

Example

<cfscript> 
    storageService1 = getCloudService(application.blobCred, application.blobConf) 
    containerList = storageService1.listAll() 
    // writeDump(containerList) 
    object1="container-object1" 
    containerobject = storageService1.container("#object1#",true); 
    containerList = storageService1.listAll() 
    // writeDump(containerList) 
    FileWrite("#ExpandPath('./')#file.txt","this test copy with access condition and storage classes"); 
    src = "file.txt" 
    blobName = "A/B/blob1" 
    uploadRequest = { 
        "srcFile" : src, 
        "blobName" : blobName 
    } 
    uploadResponse = containerobject.uploadFile(uploadRequest); 
    containerList = containerobject.listAll() 
    // writeDump(containerList) 
    // copy blob object 
    copyRequest = { 
        "source" : "container-object1/A/B/blob1", 
        "storageClass" : "HOT", 
        "blobName" : "C/D/blob2" // destination blob 
    } 
    copyResponse = containerobject.copy(copyRequest); 
    containerList = containerobject.listAll() 
    writeDump(copyResponse) 
</cfscript>

Upload a directory

Upload a directory in a container. You can also perform a bulk upload.

  • Amazon S3- Yes
  • Azure- Yes
  • Multi-cloud- Yes

Syntax

uploadDirectory(parameterStruct)

Parameters

Parameter

Description

Required

prefix

Select only those directories that begin with the specified prefix.

Yes

srcDirectory

The location of the directory to upload.

Yes

uploadNestedDirectory

True or False. Specify if you want to include sub-directories inside the main folder.

No

Example

<cfscript>
   storageService = getCloudService(application.blobCred, application.blobConf)
   object1="root-object1"

   uploadRequest = {
           "prefix" : "prefix",
           "srcDirectory" : "DirLocation",
           "uploadNestedDirectory":true
         }
   root = storageService.container("#object1#",true);
   uploadResponse = root.uploadDirectory(uploadRequest);   writeDump(uploadResponse)
 </cfscript> 

Upload file parallelly

Upload files in a root parallelly.

  • Amazon S3- Yes
  • Azure- Yes
  • Multi-cloud- Yes

Syntax

parallelUploadFile(parameterStruct)

Parameters

Parameter

Description

Required

key

The key associated with the object that you want to upload.

Yes

srcFile

The path of the file to be uploaded.

Yes

accessCondition

An AccessCondition object that represents the condition that must be met in order for the request to proceed. Valid values are:

  • leaseID
  • ifMatchETag
  • ifNoneMatchETag
  • ifModifiedSinceDate
  • ifUnmodifiedSinceDate
  • ifSequenceNumberLessThanOrEqual
  • ifSequenceNumberLessThan
  • ifSequenceNumberEqual
  • ifMaxSizeLessThanOrEqual
  • ifAppendPositionEqual

No

context

Represents the context of the current operation.

No

options

Specifies additional options for the request. If null, default options are applied to the request.

Struct containing the following:

  • MaximumExecutionTimeInMs- Int
  • TimeoutIntervalInMs- Int
  • UseTransactionalContentMD5- Bool
  • StoreBlobContentMD5- Bool
  • RetryPolicyFactory- None, Exponential, or Linear
  • LocationMode- PRIMARY_ONLY
  • EnableLogging- Bool
  • AbsorbConditionalErrorsOnRetry – Bool
  • ConcurrentRequestCount – Int
  • UseTransactionalContentMD5 – Bool
  • StoreBlobContentMD5 – Bool
  • DisableContentMD5Validation – Bool
  • SingleBlobPutThresholdInBytes- Int
  • EncryptionKey – RSA key
  • SkipEtagLocking – Bool
  • RetryPolicyFactory
    • RetryPolicyType - "EXPONENTIAL" | "LINEAR" | "NONE"
    • DeltaBackoffIntervalInMs – Int
    • MaxAttempts – Int
    • ResolvedMinBackoff - Int
  • LocationMode- "PRIMARY_ONLY" | "PRIMARY_THEN_SECONDARY" | "SECONDARY_ONLY" | "SECONDARY_THEN_PRIMARY"
  • MaximumExecutionTimeInMs – Int
  • TimeoutIntervalInMs - Intc

No

Example

<cfscript> 
    storageService = getCloudService(application.blobCred, application.blobConf) 
    object1="root-new" 
    Dirpath=#ExpandPath( ".")#&"/" 
    rootObject = storageService.root("#object1#",true) 
    FileWrite("#Dirpath#uploadfile.txt","This txt file is used to upload and download functionality for azure blob storage.") 
    src = "uploadfile.txt" 
 key = "key1" 
 uploadRequest = { 
        "srcFile" : src, 
        "key" : key, 
  "options": {"timeoutIntervalInMs":2000} 
 } 
 try{ 
        uploadResponse = rootObject.parallelUploadFile(uploadRequest) 
        writeOutput("Successfully uploaded file parallelly") 
        writeDump(uploadResponse) 
    }   
    catch(any e){ 
        writeDump(e) 
    } 
</cfscript>

Download file parallelly

Download a file in parallelly. If the size of the file is large, then the method will use multiple threads internally to download the file.

  • Amazon S3- Yes
  • Azure- Yes
  • Multi-cloud- Yes

Syntax

parallelDownloadFile(parameterStruct)

Parameters

Parameter

Description

Required

destinationFile

The name of the file to be downloaded.

Yes

filePath

The location of the destination file.

Yes

key

The key associated with the object that you want to upload.

Yes

srcFile

The path of the file to be uploaded.

Yes

accessCondition

An AccessCondition object that represents the condition that must be met in order for the request to proceed. Valid values are:

  • leaseID
  • ifMatchETag
  • ifNoneMatchETag
  • ifModifiedSinceDate
  • ifUnmodifiedSinceDate
  • ifSequenceNumberLessThanOrEqual
  • ifSequenceNumberLessThan
  • ifSequenceNumberEqual
  • ifMaxSizeLessThanOrEqual
  • ifAppendPositionEqual

No

context

Represents the context of the current operation.

No

options

Specifies additional options for the request. If null, default options are applied to the request.

Struct containing the following:

  • MaximumExecutionTimeInMs- Int
  • TimeoutIntervalInMs- Int
  • UseTransactionalContentMD5- Bool
  • StoreBlobContentMD5- Bool
  • RetryPolicyFactory- None, Exponential, or Linear
  • LocationMode- PRIMARY_ONLY
  • EnableLogging- Bool
  • AbsorbConditionalErrorsOnRetry – Bool
  • ConcurrentRequestCount – Int
  • UseTransactionalContentMD5 – Bool
  • StoreBlobContentMD5 – Bool
  • DisableContentMD5Validation – Bool
  • SingleBlobPutThresholdInBytes- Int
  • EncryptionKey – RSA key
  • SkipEtagLocking – Bool
  • RetryPolicyFactory
    • RetryPolicyType - "EXPONENTIAL" | "LINEAR" | "NONE"
    • DeltaBackoffIntervalInMs – Int
    • MaxAttempts – Int
    • ResolvedMinBackoff - Int
  • LocationMode- "PRIMARY_ONLY" | "PRIMARY_THEN_SECONDARY" | "SECONDARY_ONLY" | "SECONDARY_THEN_PRIMARY"
  • MaximumExecutionTimeInMs – Int
  • TimeoutIntervalInMs - Intc

No

Example

<cfscript> 
    storageService = getCloudService(application.blobCred, application.blobConf) 
    object1="root-download" 
    Dirpath=#ExpandPath( ".")#&"/" 
    rootObject = storageService.root("#object1#",true) 
    FileWrite("#Dirpath#uploadfile.txt","This txt file is used to upload and download functionality for azure blob storage.") 
    src = "uploadfile.txt" 
 key = "key1" 
 uploadRequest = { 
        "srcFile" : src, 
        "key" : key 
 } 
 // upload file   
    uploadResponse = rootObject.uploadFile(uploadRequest) 
    // download the same file that you have uploaded and check the content 
 FileWrite("#Dirpath#download.txt","");     
    destination = "download.txt" 
    downloadRequest = { 
        "destinationFile" : destination, 
        "key" : key, 
        "options": {"timeoutIntervalInMs":2000} 
    } 
    try{ 
        downloadResponse = rootObject.parallelDownloadFile(downloadRequest) 
        writeOutput("Successfully downloaded file parallelly") 
        writeDump(downloadResponse) 
    } 
    catch (any e){ 
        writeDump(e) 
    } 
</cfscript>

Upload an object

Upload a ColdFusion object to a root.

  • Amazon S3- Yes
  • Azure- Yes
  • Multi-cloud- Yes

Syntax

uploadObject(parameterStruct)

Parameters

Parameter

Description

Required

object

The ColdFusion object to upload.

Yes

blobName

The name of theblob where you'd upload the object to.

Yes

type

Object type- json.

No

options

Specifies additional options for the request. If null, default options are applied to the request.

Struct containing the following:

  • MaximumExecutionTimeInMs- Int
  • TimeoutIntervalInMs- Int
  • UseTransactionalContentMD5- Bool
  • StoreBlobContentMD5- Bool
  • RetryPolicyFactory- None, Exponential, or Linear
  • LocationMode- PRIMARY_ONLY
  • EnableLogging- Bool
  • AbsorbConditionalErrorsOnRetry – Bool
  • ConcurrentRequestCount – Int
  • UseTransactionalContentMD5 – Bool
  • StoreBlobContentMD5 – Bool
  • DisableContentMD5Validation – Bool
  • SingleBlobPutThresholdInBytes- Int
  • EncryptionKey – RSA key
  • SkipEtagLocking – Bool
  • RetryPolicyFactory
    • RetryPolicyType - "EXPONENTIAL" | "LINEAR" | "NONE"
    • DeltaBackoffIntervalInMs – Int
    • MaxAttempts – Int
    • ResolvedMinBackoff - Int
  • LocationMode- "PRIMARY_ONLY" | "PRIMARY_THEN_SECONDARY" | "SECONDARY_ONLY" | "SECONDARY_THEN_PRIMARY"
  • MaximumExecutionTimeInMs – Int
  • TimeoutIntervalInMs - Intc

No

Example

<cfscript> 
    storageService = getCloudService(application.blobCred, application.blobConf) 
    rootObject = storageService.root("root-upload",true) 
    // define upload struct 
    uploadRequestsstruct ={ 
        "object" : "test string for encryption", 
        "blobName" : "key001", 
        "type" :"json", 
        "options":{ 
            "maximumExecutionTimeInMs" : 1000 
        } 
    } 
    try{ 
        uploadResponse=rootObject.uploadObject(uploadRequestsstruct) 
        writeOutput("Object uploaded successfully") 
        writeDump(uploadResponse) 
    } 
    catch(any e){ 
        writeDump(e) 
    } 
</cfscript>

Download an object

Download a ColdFusion object from a root.

  • Amazon S3- Yes
  • Azure- Yes
  • Multi-cloud- Yes

Syntax

downloadObject(parameterStruct)

Parameters

Parameter

Description

Required

key

The key with which the object was uploaded.

Yes

type

Type of the ColdFusion object- json

Yes

Example

<cfscript> 
    storageService = getCloudService(application.blobCred, application.blobConf) 
    rootObject = storageService.root("root-download",true) 
    // define upload struct 
    uploadRequestsstruct ={ 
        "object" : "test string for encryption", 
        "blobName" : "key001", 
        "type" :"json", 
        "options":{ 
            "maximumExecutionTimeInMs" : 1000 
        } 
    } 
    // upload object 
    rootObject.uploadObject(uploadRequestsstruct) 
    // define download struct 
    downloadObjectStruct = { 
        "blobName" : "key001", 
        "type" :"json" 
    } 
    try{ 
        downloadResponse=rootObject.downloadObject(downloadObjectStruct) 
        writeOutput("Downloaded the object successfully") 
        writeDump(downloadResponse) 
    } 
    catch(any e){ 
        writeDump(e) 
    } 
</cfscript>

Create a container

A container serves as a default container for your storage account. A storage account may have one container container. A blob stored in the container container may be addressed without referencing the container container name. For more information, see Azure Blob container.

Use the method container to create the container container. The method accepts two parameters:

  • Name of the container (required)
  • Public access type (optional): The parameter publicAccessType defines the level at which the access will be granted. This parameter can accept one of the four values:
    • BLOB: Specifies blob-level public access. Clients can read the content and metadata of blobs within this container but cannot read container metadata or list the blobs within the container.
    • CONTAINER: Specifies container-level public access. Clients can read blob content and metadata and container metadata and can list the blobs within the container.
    • OFF: Specifies no public access. Only the account owner can access resources in this container.

Create a snapshot

A blob snapshot is a read-only version of a blob that's taken at a single point in time. After a snapshot has been created, it can be read, copied, or deleted, but not modified. Snapshots provide a way to back up a blob as it appears at a moment in time.

A blob may have any number of snapshots. Snapshots persist until they're explicitly deleted. A snapshot can't outlive its source blob. You can enumerate the snapshots associated with your blob to track your current snapshots.

For more information, see Snapshots in Azure Blob.

Syntax

createSnapshot(parameterStruct)

Parameters

Parameter

Description

Required

blobName

The name of the blob whose snapshot you want to create.

Yes

keyName

The key associated with the blob.

Yes

Example

<cfscript> 
  storageService = getCloudService(application.blobCred, application.blobConf) 
  // create container 
  container = storageService.container("con001",true) 
  src = "#ExpandPath('./')#file.txt" 
  //writedump(src) 
  blobname = "Version-1" 
  // upload a file into the blob 
  uploadRequest = { 
    "srcFile" : src, 
    "blobName" : blobname 
  } 
  uploadResponse = container.uploadFile(uploadRequest) 
  //writeDump(uploadResponse) 
  // Create snapshot 
  // Create snapshot struct 
  versionRequest = { 
        "blobName" : "Version-1" 
      } 
  snapshot1 = container.Createsnapshot(versionRequest); 
  snapshot2 = container.Createsnapshot(versionRequest); 
  writeDump(snapshot1) 
  writeDump(snapshot2) 
</cfscript> 

Copy container in different account

Copy the blob in different account by using storage classes.

Example

<cfscript>  
  storageService1 = getCloudService(application.blobCred, application.blobConf) 
  rootList = storageService1.listAll() 
   
  for (i=1;i LTE ArrayLen(rootList);i=i+1) 
   { 
   if( (i GT 0 ) and (rootList[i].name Neq "rootpoc") ){ 
    storageService1.delete(rootList[i].name)} 
   } 
  sleep(35000) 
  rootobject = storageService1.container("#object1#",true); 
  rootList = storageService1.listAll() 
  FileWrite("#Dirpath#uploadfile.txt","this test copy with access condition and storage classes"); 
    src = "uploadfile.txt" 
    blobName = "A/B/key1" 
        uploadRequest = { 
            "srcFile" : src, 
            "blobName" : blobName 
        } 
    uploadResponse = rootobject.uploadFile(uploadRequest); 
 rootList = rootobject.listAll() 
 
 copyRequest = { 
        "source" : "root-object1/A/B/key1", 
        "storageClass" : "HOT", 
        "blobName" : "C/D/Key2" 
    } 
 copyResponse = rootobject.copy(copyRequest); 
 rootList = rootobject.listAll() 
 for (i=1;i LTE ArrayLen(rootList.response);i=i+1) 
 { 
  if(rootList.response[i].blobName eq "C/D/Key2"){ 
   writeoutput(rootList.response[i].properties.standardBlobTier & " ")} 
  } 
 writeoutput(copyResponse.status) 
</cfscript>

Create a version

Create a version for a blob. You can enable versioning to automatically maintain previous versions of blob.

For more information, see Blob versioning.

Syntax

createVersion(parameterStruct)

Parameters

Parameter

Description

Required

blobName

The name of the blob whose snapshot you want to create.

Yes

keyName

The key associated with the blob.

Yes

Example

<cfscript> 
  storageService = getCloudService(application.blobCred, application.blobConf) 
  object1="root-object1" 
  FileWrite("#ExpandPath('./')#file.txt","this test copy with access condition and storage classes"); 
  rootobject = storageService.root("#object1#",true); 
  src = "file.txt" 
  key = "Version-1" 
  uploadRequest = { 
    "srcFile" : src, 
    "key" : key 
  } 
  uploadResponse = rootobject.uploadFile(uploadRequest); 
  writeDump(uploadResponse) 
  versionRequest = { 
    "key" : "Version-1" 
  } 
  Version1 = rootobject.createversion(versionRequest); 
  Version2 = rootobject.createversion(versionRequest); 
  writeDump(Version1) 
  writeDump(Version2) 
</cfscript>

Apply a policy on a Blob

A stored access policy provides an additional level of control over service-level shared access signatures (SAS) on the server side. 

You can use a stored access policy to change the start time, expiry time, or permissions for a signature, or to revoke it after it has been issued.

For more information, see Access policy.

Syntax

putPolicy(parameterStruct)

Parameters

Parameter

Description

Required

permissions

Specifies the array of possible permissions for a shared access policy. Values are:

  • ADD
  • CREATE
  • DELETE
  • LIST
  • READ
  • WRITE

No

sharedAccessStartTime

Specifies the time when access is granted.

No

sharedAccessExpiryTime

Specifies the time when the access expires.

No

Example

<cfscript> 
    storageService = getCloudService(application.blobCred, application.blobConf) 
     
    // create container 
    container = storageService.container("con002",true) 
    // Uploads the container's permissions using the specified request options and operation context. 
    // policy struct 
    policyStruct = { 
        "publicAccessType" : "OFF", //BLOB,CONTAINER 
        "sharedAccessPolicies" : { 
            "policyName1" : { 
                    "permissions" : ["READ", "ADD"], 
                    "sharedAccessExpiryTime" : "31/12/2019", 
                    "sharedAccessStartTime" : "17/12/2019" 
                }, 
            "policyName2" : { 
                    "permissions" : ["READ", "ADD"], 
                    "sharedAccessExpiryTime" : "31/12/2019", 
                    "sharedAccessStartTime" : "17/12/2019" 
                } 
        } 
    } 
    putPolicyResponse=container.putPolicy(policyStruct); 
    writeDump(putPolicyResponse) 
    getPolicyResponse=container.getPolicies() 
    writeOutput("<br/>" & "List of all policies") 
    writeDump(getPolicyResponse) 
</cfscript> 

Get policies on a blob

Get the policies that you had applied on a blob.

Syntax

getPolicies()

Example

<cfscript> 
    storageService = getCloudService(application.blobCred, application.blobConf) 
     
    // create container 
    container = storageService.container("con002",true) 
    // Uploads the container's permissions using the specified request options and operation context. 
    // policy struct 
    policyStruct = { 
        "publicAccessType" : "OFF", //BLOB,CONTAINER 
        "sharedAccessPolicies" : { 
            "policyName1" : { 
                    "permissions" : ["READ", "ADD"], 
                    "sharedAccessExpiryTime" : "31/12/2019", 
                    "sharedAccessStartTime" : "17/12/2019" 
                }, 
            "policyName2" : { 
                    "permissions" : ["READ", "ADD"], 
                    "sharedAccessExpiryTime" : "31/12/2019", 
                    "sharedAccessStartTime" : "17/12/2019" 
                } 
        } 
    } 
    putPolicyResponse=container.putPolicy(policyStruct); 
    writeDump(putPolicyResponse) 
    getPolicyResponse=container.getPolicies() 
    writeOutput("<br/>" & "List of all policies") 
    writeDump(getPolicyResponse) 
</cfscript>

Delete policies on a blob

Delete the policies that you had applied on a blob.

Syntax

deletePolicies()

Example

<cfscript> 
    storageService = getCloudService(application.blobCred, application.blobConf) 
     
    // create container 
    container = storageService.container("con002",true) 
    // Uploads the container's permissions using the specified request options and operation context. 
    // policy struct 
    policyStruct = { 
        "publicAccessType" : "OFF", //BLOB,CONTAINER 
        "sharedAccessPolicies" : { 
            "policyName1" : { 
                    "permissions" : ["READ", "ADD"], 
                    "sharedAccessExpiryTime" : "31/12/2019", 
                    "sharedAccessStartTime" : "17/12/2019" 
                }, 
            "policyName2" : { 
                    "permissions" : ["READ", "ADD"], 
                    "sharedAccessExpiryTime" : "31/12/2019", 
                    "sharedAccessStartTime" : "17/12/2019" 
                } 
        } 
    } 
    putPolicyResponse=container.putPolicy(policyStruct); 
    writeDump(putPolicyResponse) 
    getPolicyResponse=container.getPolicies() 
    writeOutput("<br/>" & "List of all policies") 
    writeDump(getPolicyResponse) 
    // delete policies 
    try{ 
        deletePolicyResponse=container.deletePolicies() 
        writeOutput("Policy deleted successfully") 
        writeDump(deletePolicyResponse) 
    } 
    catch(any e){ 
        writeDump(e) 
    } 
</cfscript>

Generate a Shared Access Signature (SAS)

A shared access signature (SAS) provides secure delegated access to resources in your storage account without compromising the security of your data. With a SAS, you have granular control over how a client can access your data. You can control what resources the client may access, what permissions they have on those resources, and how long the SAS is valid, among other parameters.

For more information, Azure Blob SAS.

Syntax

generateSas(parameterStruct)

Parameters

Parameter

Description

Required

blob

The blob that you want to enforce SAS permissions on.

Yes

policy

Struct containing the following:

permissions: Specifies the array of possible permissions for a shared access policy. Values are:

  • ADD
  • CREATE
  • DELETE
  • LIST
  • READ
  • WRITE

sharedAccessStartTime: Specifies the time when access is granted.

sharedAccessExpiryTime: Specifies the time when the access expires.

Yes

headers

Struct containing the following:

  • cacheControl
  • contentDisposition
  • contentEncoding
  • contentLanguage
  • contentType
  • groupPolicyIdentifier
  • ipRange
  • protocols: HTTPS_HTTP | HTTPS_ONLY

No

Example

<cfscript> 
  // A shared access signature (SAS) provides secure delegated access to resources in your storage 
  // account without compromising the security of your data. 
  // With a SAS, you have granular control over how a client can access your data. 
  // You can control what resources the client may access, what permissions they have on those resources, 
  // and how long the SAS is valid, among other parameters. 
  storageService = getCloudService(application.blobCred, application.blobConf) 
  object1="root-object1" 
  root = storageService1.container("#object1#",true) 
  FileWrite("#ExpandPath('./')#file.txt","Sgt. Pepper's Lonely Hearts Club Band") 
  src = "file.txt" 
  blobName = "key1" 
  uploadRequest = { 
    "srcFile" : src, 
    "blobName" : blobName 
  } 
  uploadResponse = root.uploadFile(uploadRequest) 
  expdate= DatePart("d",now())+2; 
  month= DatePart("m",now()) 
  year= DatePart("yyyy",now()) 
  startdate=DatePart("d",now()); 
  sasRequest ={ 
      "blobName" :  "key1", 
      "policy" : { 
                  "permissions" : ["READ"], 
                  "sharedAccessExpiryTime" : "#month#/#Expdate#/#year#", 
                  "sharedAccessStartTime" : "#month#/#startdate#/#year#" 
              } 
  } 
    sharedAccessSignature = root.generateSas(sasRequest); 
    writedump(sharedAccessSignature) 
</cfscript> 

Upload a directory

Upload a directory in a blob. You can also perform a bulk upload.

Syntax

uploadDirectory(parameterStruct)

Parameters

Parameter

Description

Required

prefix

Select only those directories that begin with the specified prefix.

No

directoryPath

The location of the directory to upload.

Yes

isIncludeSubDirectories

True or False. Specify if you want to include sub-directories inside the main folder.

No

Example

<cfscript> 
  storageService = getCloudService(application.blobCred, application.blobConf) 
  object1="root-object1" 
  //writeDump(rootList) 
  FileWrite("#ExpandPath('./')#/uploadfile.txt","This txt file is used to upload and download functionality for azure blob storage.") 
  src = "uploadfile.txt" 
  destination = "download.txt" 
  blobName = "key1" 
  uploadRequest = { 
          "srcFile" : src, 
          "blobName" : blobName 
        } 
  root = storageService.container("#object1#",true); 
  uploadResponse = root.uploadFile(uploadRequest); 
  writeDump(uploadResponse) 
</cfscript> 

Acquire lease

A lease on a Blob enables you to be granted ownership to a Blob. After you have been granted the lease, you can then update the Blob or delete the Blob. When a Blob is leased, other processes can still read it, but any attempt to update it will fail.

For more information, see Blob containers- lease.

Syntax

acquireLease(parameterStruct)

Parameters

Parameter

Description

Required

leaseTimeInSeconds

The duration of the lease.

Yes

proposedLeaseID

The ID of the created lease on the blob.

No

Example

<cfscript> 
  // Acquire lease and check lease acquire status. 
  storageService = getCloudService(application.blobCred, application.blobConf) 
  object1="root-object1" 
  root = storageService1.container("#object1#",true); 
  FileWrite("#ExpandPath('./')#/uploadfile.txt","Coldfusion2020 lease-related operation."); 
    src = "uploadfile.txt" 
    blobName = "key1" 
    uploadRequest = { 
          "srcFile" : src, 
          "blobName" : blobName 
      } 
  uploadResponse = root.uploadFile(uploadRequest) 
  acquireLeaseRequest = { 
        "blobName":blobName, 
        "leaseDurationInSeconds": 15, 
        "proposedLeaseId": "lease01" 
        } 
 
  acqLeaseResponse=root.acquireLease(acquireLeaseRequest) 
  writeDump(acqLeaseResponse) 
</cfscript>

Renew lease

Once you’ve acquired a lease to a blob, you can renew the lease.

Syntax

renewLease(parameterStruct)

Parameters

Parameter

Description

Required

leaseTimeInSeconds

The lease duration to renew.

Yes

proposedLeaseID

The ID of the lease.

No

Example

<cfscript> 
  // Acquire lease and check lease acquire status. 
  object1="root-object1" 
  storageService1 = getCloudService(application.blobCred, application.blobConf) 
  root = storageService1.container("#object1#",true); 
  // Acquire lease and check lease acquire status. 
  Dirpath=#ExpandPath( ".")#&"/" 
  root = storageService1.container("#object1#",true); 
  FileWrite("#Dirpath#uploadfile.txt","Coldfusion2020 lease related operation"); 
  src = "uploadfile.txt" 
  blobName = "key1" 
  uploadRequest = { 
          "srcFile" : src, 
          "blobName" : blobName 
  } 
  uploadResponse = root.uploadFile(uploadRequest) 
  acquireLeaseRequest = { 
        "blobName":blobName, 
        "leaseDurationInSeconds": 15, 
        "proposedLeaseId": "dddddddddddddddddddddddddddddddd" 
        } 
 
  root.acquireLease(acquireLeaseRequest) 
  // Renew existing lease 
  sleep(16000) 
  renewLeaseRequest = { 
      "blobName":blobName, 
      "accessCondition" : { "leaseID" :"dddddddddddddddddddddddddddddddd"  } 
      } 
  renewLeaseResponse=root.renewLease(renewLeaseRequest) 
  writeDump(renewLeaseResponse) 
</cfscript>

Change lease

Once you’ve acquired a lease to a blob, you can renew the lease.

Syntax

changeLease(parameterStruct)

Parameters

Parameter

Description

Required

leaseTimeInSeconds

The lease duration to change.

Yes

proposedLeaseID

The ID of the lease.

No

Example

<cfscript> 
  // Acquire lease and check lease acquire status. 
  object1="root-object1" 
  storageService1 = getCloudService(application.blobCred, application.blobConf) 
  root = storageService1.container("#object1#",true); 
  // Acquire lease and check lease acquire status. 
  Dirpath=#ExpandPath( ".")#&"/" 
  root = storageService1.container("#object1#",true); 
  FileWrite("#Dirpath#uploadfile.txt","Coldfusion 2020 lease related operation"); 
    src = "uploadfile.txt" 
    blobName = "key1" 
    uploadRequest = { 
          "srcFile" : src, 
          "blobName" : blobName 
      } 
  uploadResponse = root.uploadFile(uploadRequest) 
 
  //acquire lease 
  acquireLeaseRequest = { 
        "blobName":blobName, 
        "leaseDurationInSeconds": 15, 
        "proposedLeaseId": "dddddddddddddddddddddddddddddddd" 
        } 
 
  root.acquireLease(acquireLeaseRequest) 
  //To change existing lease 
    changeLeaseRequest = { 
        "blobName":blobName, 
        "proposedLeaseId": "ddddddddddddddcccccccccccccccccc", 
        "accessCondition" : { "leaseID" :"ddddddddddddddddcddddddddddddddd"  } 
        } 
  changeleaseid=root.changeLease(changeLeaseRequest) 
  writeDump(changeleaseid) 
</cfscript>

Release lease

You can change the lease of the blob, that you had previously acquired.

Syntax

releaseLease(parameterStruct)

Parameters

Parameter

Description

Required

blobPath

The path of the blob whose lease has to be renewed.

Yes

leaseID

The ID of the lease.

No

Example

<cfscript> 
  // Acquire lease and check lease acquire status. 
  object1="root-object1" 
  storageService1 = getCloudService(application.blobCred, application.blobConf) 
  root = storageService1.container("#object1#",true); 
  // Acquire lease. 
  Dirpath=#ExpandPath( ".")#&"/" 
  root = storageService1.container("#object1#",true); 
  FileWrite("#Dirpath#uploadfile.txt","Coldfusion2020 lease related operation"); 
    src = "uploadfile.txt" 
    blobName = "key1" 
    uploadRequest = { 
          "srcFile" : src, 
          "blobName" : blobName 
      } 
  uploadResponse = root.uploadFile(uploadRequest) 
  acquireLeaseRequest = { 
        "blobName":blobName, 
        "leaseDurationInSeconds": 60, 
        "proposedLeaseId": "dddddddddddddddddddddddddddddddd" 
        } 
 
  root.acquireLease(acquireLeaseRequest) 
  // Release the existing lease 
  changeLeaseRequest = { 
      "blobName":blobName, 
      "accessCondition" : { "leaseID" :"dddddddddddddddddddddddddddddddd"  } 
  } 
  releaseResponse=root.releaseLease(changeLeaseRequest) 
  writeDump(releaseResponse) 
</cfscript>

Break lease

You can terminate the lease. Any other cannot acquire a new lease until the current lease period has expired.

Syntax

breakLease(parameterStruct)

Parameters

Parameter

Description

Required

blobPath

The path of the blob whose lease has to be terminated.

Yes

leaseID

The ID of the lease.

No

Example

<cfscript> 
  // Acquire lease and check lease acquire status. 
  object1="root-object1" 
  storageService1 = getCloudService(application.blobCred, application.blobConf) 
  root = storageService1.container("#object1#",true); 
  // Acquire lease. 
  Dirpath=#ExpandPath( ".")#&"/" 
  root = storageService1.container("#object1#",true); 
  FileWrite("#Dirpath#uploadfile.txt","Coldfusion2020 lease related operation"); 
  src = "uploadfile.txt" 
  blobName = "key1" 
  uploadRequest = { 
        "srcFile" : src, 
        "blobName" : blobName 
    } 
  uploadResponse = root.uploadFile(uploadRequest) 
  acquireLeaseRequest = { 
      "blobName":blobName, 
      "leaseDurationInSeconds": 60, 
      "proposedLeaseId": "dddddddddddddddddddddddddddddddd" 
      } 
 
  root.acquireLease(acquireLeaseRequest) 
  //To break lease existing lease 
    breakleaserequest = { 
        "blobName":blobName, 
        "accessCondition" : { "leaseID" :"dddddddddddddddddddddddddddddddd"  } 
        } 
  breakLeaseResponse=root.breakLease(breakleaserequest) 
  writeDump(breakLeaseResponse) 
</cfscript>

Client-side encryption

In ColdFusion, you can use an RSA encryption key while uploading a blob. While downloading the same blob, you must provide the same RSA encryption key with password.

All data that is stored in Azure storage is automatically encrypted before uploading and decrypted during retrieval. Encryption and decryption are completely transparent to the user. All data is encrypted using 256-bit AES encryption. With encryption enabled by default, you need not make any changes to their applications.

getKeyPairfromkeystore

Import a key pair from a key store that is in your computer.

A JKS or a keystore is an encrypted security file that is used to store a set of cryptographic keys or certificates in the binary format, and it requires a password to be opened.

Syntax

getKeyPairfromkeystore(parameterStruct)

Parameters

Parameter

Description

keystore

Location of the keystore or jks file.

keystorePassword

Password of the jks file.

keypairPassword

Password of RSA keypair.

keystoreAlias

Alias name of the jks keystore.

keyStoreType

Jks or pkcs12.

Example- p12 key

<cfscript> 
    storageService = getCloudService(application.blobCred, application.blobConf) 
    keyPair2 = getKeyPairfromkeystore({  
        "keystore": ExpandPath("blobkey.p12"),  
        "keystorePassword": "changeit"  
    }) 
    // create a root 
    rootobject = storageService.root("root001",true); 
    uploadRequestsstruct ={ 
        "object" : "Encryption 001", 
        "key" : "key001", 
        "type" :"json", 
        "options" : { 
            "encryption":{  
                "keypair": keyPair2,  
                "kid": "sample"  
            } 
        } 
    } 
    uploadResponse = rootobject.uploadObject(uploadRequest=uploadRequestsstruct) 
    writeDump(uploadResponse) 
</cfscript>

Example- jks key

<cfscript> 
    storageService = getCloudService(application.blobCred, application.blobConf) 
    // create a root 
    rootobject = storageService.root("root002",true) 
    // create jks struct 
    keyPair2 = getKeyPairfromkeystore({  
        "keystore": ExpandPath("blobkey.jks"),  
        "keystorePassword": "changeit",  
        "keypairPassword": "changeit",  
        "keystoreAlias": "alias3",  
        "keyStoreType": "jks"  
    }) 
    // create upload struct 
    uploadRequestsstruct ={ 
        "object" : "Object 002", 
        "key" : "key", 
        "type" :"json", 
        "options" : { 
            "encryption":{ "keypair": keyPair2, "kid": "sample" }} 
        } 
    uploadResponse = rootobject.uploadObject(uploadRequest=uploadRequestsstruct) 
    writeDump(uploadResponse) 
</cfscript>

Download object with p12 key

<cfscript> 
    storageService = getCloudService(application.blobCred, application.blobConf) 
    // create keypair struct 
    keyPair2 = getKeyPairfromkeystore({  
        "keystore": ExpandPath("blobkey.p12"),  
        "keystorePassword": "changeit"  
    }) 
    // create root 
    rootobject = storageService.root("root003",true); 
    // upload struct 
    uploadRequestsstruct ={ 
            "object" : "Test string azureb blob for encryption", 
            "key" : "key", 
            "type" :"json", 
            "options" : { 
                "encryption":{ "keypair": keyPair2, "kid": "sample" }} 
            } 
    uploadResponse = rootobject.uploadObject(uploadRequest=uploadRequestsstruct); 
    // download struct 
    downloadStruct = { 
        "key" : "key", 
        "type" :"json", 
        "options" : {"encryption":{ "keypair": keyPair2, "kid": "sample" }} 
    } 
    try{ 
        downloadResponse =rootobject.downloadObject(downloadStruct) 
        if(downloadResponse.object=="Test string azureb blob for encryption" &&  
           uploadResponse.status=="success" && 
           downloadResponse.status=="success") 
        writeOutput("Object downloaded successfully") 
    } 
    catch(any e) 
    { 
        writeDump(e) 
    } 
</cfscript>

Download object using jks key

<cfscript> 
    storageService = getCloudService(application.blobCred, application.blobConf) 
    // create root 
    rootobject = storageService.root("root004",true) 
    //create keypair struct 
    keyPair2 = getKeyPairfromkeystore({  
        "keystore": ExpandPath("blobkey.jks"),  
        "keystorePassword": "changeit",  
        "keypairPassword": "changeit",  
        "keystoreAlias": "alias3",  
        "keyStoreType": "jks"  
    }) 
    // create object upload struct 
    uploadRequestsstruct ={ 
        "object" : "Test string azureb blob for encryption", 
        "key" : "key", 
        "type" :"json", 
        "options" : { 
            "encryption":{ "keypair": keyPair2, "kid": "sample" }} 
        } 
    uploadResponse = rootobject.uploadObject(uploadRequest=uploadRequestsstruct); 
    // create object download struct    
    downloadObject = { 
        "key" : "key", 
        "type" :"json", 
        "options" : { 
            "encryption":{ "keypair": keyPair2, "kid": "sample" }} 
    } 
    try{ 
        downloadResponse =rootobject.downloadObject(downloadObject) 
        if( 
            downloadResponse.object=="Test string azureb blob for encryption" &&  
            uploadResponse.status=="success" && 
            downloadResponse.status=="success") 
        writeOutput("Object downloaded successfully") 
    } 
    catch(any e) 
    { 
        writeDump(e); 
    } 
</cfscript>

Upload a file in blocks

Optimize uploads of large amounts of data using the method blockUpload. Block blobs are comprised of blocks, each of which is identified by a block ID.

For more information, see Block blobs.

Syntax

blockUpload(parameterStruct)

Parameters

Parameter

Description

Required

blockId

The ID of the block of blob that you want to upload.

Yes

blobName

The name of the blob to upload.

Yes

srcFile

The path of the file to be uploaded.

Yes

Example

<cfscript> 
 
try{ 
   blobAccount = getcloudService(application.blobCred, application.blobConf); 
    rootList = blobAccount.listAll() 
    for (i=1;i LTE ArrayLen(rootList);i=i+1) 
  { 
       if( (rootList[i].name eq "testcontainer") ){ 
       blobAccount.delete(rootList[i].name) 
             sleep(35000) 
        } 
  } 
   
    root = blobAccount.container("testcontainer", true); 
    blobname = "Suite.zip" 
        createPartFileRequest = {  
        "srcFile":blobname, 
        "blockSizeInBytes": 102400, 
        "destinationDirectory": "Destination" 
        } 
    respt = root.createPartFiles(createPartFileRequest) 
    blockIds = ArrayNew(1); 
    blockIdItr = "ddd" 
    count=1 
    for(partFile in respt["partFiles"]) { 
        bid=""&(1000 + count)  //toBase64(URLEncodedFormat("ddd"&count)) 
        
        structUpload = { 
            "blockId": bid, 
            "blobName": blobName, 
            "srcFile": partFile 
        } 
        respt = root.blockUpload(structUpload); 
        
        arrayAppend(blockIds, bid) 
        count=count+1 
    } 
  
 commitBlockList = { 
        "blockIds": blockIds, 
        "blobName": blobName 
    } 
    respt = root.commitBlockList(commitBlockList); 
     if(respt.status=="SUCCESS") 
            writeOutput("Successful upload!") 
} 
 
catch(any e) 
{ 
    writeDump(e) 
} 
</cfscript>

Upload blob metadata

This method is used to upload metadata details for blob.

Syntax

uploadMetadata(parameterStruct)

Parameters

Parameter

Description

Required

key

The key associated with the blob.

Yes

metadata

Struct that contains the following:

  • details

Yes

Example

<cfscript>  
try{ 
  storageService1 = getcloudService(this.blobCred, this.blobConf); 
  rootList = storageService1.listAll() 
   
  for (i=1;i LTE ArrayLen(rootList);i=i+1) 
   { 
   if( (i GT 0 )){ 
    storageService1.delete(rootList[i].name)} 
   } 
  sleep(35000) 
  rootobject = storageService1.root("#object1#",true); 
  FileWrite("#Dirpath#UploadTest.txt","Test1.txt uploaded") 
    src = "UploadTest.txt" 
    key = "A/B/Test1" 
        uploadRequest = { 
            "srcFile" : src, 
            "key" : key 
        } 
    uploadResponse = rootobject.uploadFile(uploadRequest); 
 
  uploadMetadata = { 
    "key" : "A/B/Test1", 
    "metadata" : { 
      "Details" : "Test1.txt uploaded" 
      } 
     } 
  response =rootobject.uploadMetadata(uploadMetadata); 
  writeoutput(response.status&" "); 
  blobStruct = { 
     "prefix" : "", 
     "isFlatListing" : "true", 
     "listingDetails" :["METADATA"] 
      } 
 rootList = rootobject.listAll(blobStruct) 
 if(rootList.response[1].metadata["Details"] EQ "Test1.txt uploaded") 
 { 
 writeoutput("Uploaded successfully") 
 } 
} 
catch(any e) 
{ 
 writedump(e); 
} 
</cfscript>

Divide file into multiple blocks

Thi method, createPartFiles, is used to break file into multiple block, while uploading a file into multiple blocks.

Syntax

createPartFiles(parameterStruct)

Parameters

  • srcFile
  • blockSizeInBytes
  • destinationDirectory

Example

<cfscript> 
 
try{ 
   blobAccount = getcloudService(application.blobCred, application.blobConf); 
    rootList = blobAccount.listAll() 
    for (i=1;i LTE ArrayLen(rootList);i=i+1) 
  { 
       if( (rootList[i].name eq "testcontainer") ){ 
       blobAccount.delete(rootList[i].name) 
             sleep(35000) 
        } 
  } 
   
    root = blobAccount.container("testcontainer", true); 
    blobname = "Suite.zip" 
        createPartFileRequest = {  
        "srcFile":blobname, 
        "blockSizeInBytes": 102400, 
        "destinationDirectory": "Destination" 
        } 
    respt = root.createPartFiles(createPartFileRequest) 
    blockIds = ArrayNew(1); 
    blockIdItr = "ddd" 
    count=1 
    for(partFile in respt["partFiles"]) { 
        bid=""&(1000 + count)  //toBase64(URLEncodedFormat("ddd"&count)) 
        
        structUpload = { 
            "blockId": bid, 
            "blobName": blobName, 
            "srcFile": partFile 
        } 
        respt = root.blockUpload(structUpload); 
        
        arrayAppend(blockIds, bid) 
        count=count+1 
    } 
  
 commitBlockList = { 
        "blockIds": blockIds, 
        "blobName": blobName 
    } 
    respt = root.commitBlockList(commitBlockList); 
     if(respt.status=="SUCCESS") 
            writeOutput("Successful upload!") 
} 
 
catch(any e) 
{ 
    writeDump(e) 
} 
</cfscript>

List all commit blocks

The method, commitBlockList, lists down all the commit blocks.

Syntax

createPartFiles(parameterStruct)

Parameters

  • blockIds
  • blobName

Example

<cfscript> 
try{ 
   blobAccount = getcloudService(application.blobCred, application.blobConf); 
    rootList = blobAccount.listAll() 
    for (i=1;i LTE ArrayLen(rootList);i=i+1) 
  { 
       if( (rootList[i].name eq "testcontainer") ){ 
       blobAccount.delete(rootList[i].name) 
             sleep(35000) 
        } 
  } 
   
    root = blobAccount.container("testcontainer", true); 
    blobname = "perfSuite.zip" 
    createPartFileRequest = {  
        "srcFile":blobname, 
        "blockSizeInBytes": 102400, 
        "destinationDirectory": "Destination" 
        } 
    respt = root.createPartFiles(createPartFileRequest) 
    blockIds = ArrayNew(1); 
    blockIdItr = "ddd" 
    count=1 
    for(partFile in respt["partFiles"]) { 
        bid=""&(1000 + count) //toBase64(URLEncodedFormat("ddd"&count)) 
        
        structUpload = { 
            "blockId": bid, 
            "blobName": blobName, 
            "srcFile": partFile 
        } 
        respt = root.blockUpload(structUpload); 
        
        arrayAppend(blockIds, bid) 
        count=count+1 
    } 
  
 commitBlockList = { 
        "blockIds": blockIds, 
        "blobName": blobName 
    } 
    respt = root.commitBlockList(commitBlockList); 
     if(respt.status=="SUCCESS") 
            writeOutput("Uploaded") 
} 
 
catch(any e) 
{ 
    writeDump(e) 
} 
</cfscript>

 Adobe

Recevez de l’aide plus rapidement et plus facilement

Nouvel utilisateur ?