Navigate to <CF_HOME>/cfusion/bin.
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 (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.
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.
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:
Navigate to <CF_HOME>/cfusion/bin.
Enter the command:
Enter the command, install azureblob.
Wait for the Azure Blob package to get installed.
For more information, see ColdFusion Package Manager.
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:
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.
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.
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.
In the ColdFusion Administrator, click Data & Services > Cloud Configuration.
Enter the following details, like configuration Alias, Vendor, and the name of the service.
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:
For more information, see Cloud configuration options.
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")
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" } } }
blobObject = getCloudService(application.blobCred, application.blobConf)
On a CFM page, you can specify the Blob credentials and configuration options in one of the four methods, specified below:
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>
<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>
<cfscript> // Using config alias and struct for service credentials // blob credentials blobCreds={ "vendorName" : "AZURE", "connectionString" : "xxxxxx" } blobObject= getCloudService(blobCreds, "blobConf") // code below ..................................... </cfscript>
<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>
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).
<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>
<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>
You can also set up SQS credential and configuration via the CFSetup configuration utility.
Add cloud credential
Set credential
Add cloud configuration
Set configuration
Create the root object. If the root doesn't exist, the root gets created.
root(rootName, createIfNotExists)
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 |
<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 the root object with additional parameters.
createRoot(parameterStruct)
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:
|
No |
<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>
Get the list of root objects in the storage account.
listAll(parameterStruct)
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:
|
No |
<cfscript> storageService = getCloudService(application.blobCred, application.blobConf) // list all blobs blobList=storageService.listAll() writeDump(blobList) </cfscript>
Delete a blob and its snaphot.
delete(parameterStruct)
Parameter |
Description |
Required |
---|---|---|
key |
The name of the blob to delete. |
Yes |
deleteSnapshotsOption |
Specify the blob snapshot to delete. Valid values are:
|
No |
<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>
You can upload a file to a container.
For more information, see Upload file to a blob.
uploadFile(parameterStruct)
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:
|
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 |
<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 a file from a container.
downloadToFile(parameterStruct)
Parameter |
Description |
Required |
---|---|---|
destinationFile |
The path where you want to download the file. |
Yes |
key |
The key associated with the container. |
Yes |
<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 a blob to another blob.
copy(paramerStruct)
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:
|
No |
key |
The key associated with the blob. |
Yes |
<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 in a container. You can also perform a bulk upload.
uploadDirectory(parameterStruct)
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 |
<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 files in a root parallelly.
parallelUploadFile(parameterStruct)
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:
|
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:
|
No |
<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 a file in parallelly. If the size of the file is large, then the method will use multiple threads internally to download the file.
parallelDownloadFile(parameterStruct)
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:
|
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:
|
No |
<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 a ColdFusion object to a root.
uploadObject(parameterStruct)
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:
|
No |
<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 a ColdFusion object from a root.
downloadObject(parameterStruct)
Parameter |
Description |
Required |
---|---|---|
key |
The key with which the object was uploaded. |
Yes |
type |
Type of the ColdFusion object- json |
Yes |
<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>
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:
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.
createSnapshot(parameterStruct)
Parameter |
Description |
Required |
---|---|---|
blobName |
The name of the blob whose snapshot you want to create. |
Yes |
keyName |
The key associated with the blob. |
Yes |
<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 the blob in different account by using storage classes.
<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 for a blob. You can enable versioning to automatically maintain previous versions of blob.
For more information, see Blob versioning.
createVersion(parameterStruct)
Parameter |
Description |
Required |
---|---|---|
blobName |
The name of the blob whose snapshot you want to create. |
Yes |
keyName |
The key associated with the blob. |
Yes |
<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>
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.
putPolicy(parameterStruct)
Parameter |
Description |
Required |
---|---|---|
permissions |
Specifies the array of possible permissions for a shared access policy. Values are:
|
No |
sharedAccessStartTime |
Specifies the time when access is granted. |
No |
sharedAccessExpiryTime |
Specifies the time when the access expires. |
No |
<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 the policies that you had applied on a blob.
getPolicies()
<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 the policies that you had applied on a blob.
deletePolicies()
<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>
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.
generateSas(parameterStruct)
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:
sharedAccessStartTime: Specifies the time when access is granted. sharedAccessExpiryTime: Specifies the time when the access expires. |
Yes |
headers |
Struct containing the following:
|
No |
<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 in a blob. You can also perform a bulk upload.
uploadDirectory(parameterStruct)
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 |
<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>
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.
acquireLease(parameterStruct)
Parameter |
Description |
Required |
---|---|---|
leaseTimeInSeconds |
The duration of the lease. |
Yes |
proposedLeaseID |
The ID of the created lease on the blob. |
No |
<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>
Once you’ve acquired a lease to a blob, you can renew the lease.
renewLease(parameterStruct)
Parameter |
Description |
Required |
---|---|---|
leaseTimeInSeconds |
The lease duration to renew. |
Yes |
proposedLeaseID |
The ID of the lease. |
No |
<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>
Once you’ve acquired a lease to a blob, you can renew the lease.
changeLease(parameterStruct)
Parameter |
Description |
Required |
---|---|---|
leaseTimeInSeconds |
The lease duration to change. |
Yes |
proposedLeaseID |
The ID of the lease. |
No |
<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>
You can change the lease of the blob, that you had previously acquired.
releaseLease(parameterStruct)
Parameter |
Description |
Required |
---|---|---|
blobPath |
The path of the blob whose lease has to be renewed. |
Yes |
leaseID |
The ID of the lease. |
No |
<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>
You can terminate the lease. Any other cannot acquire a new lease until the current lease period has expired.
breakLease(parameterStruct)
Parameter |
Description |
Required |
---|---|---|
blobPath |
The path of the blob whose lease has to be terminated. |
Yes |
leaseID |
The ID of the lease. |
No |
<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>
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.
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.
getKeyPairfromkeystore(parameterStruct)
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. |
<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>
<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>
<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>
<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>
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.
blockUpload(parameterStruct)
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 |
<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>
This method is used to upload metadata details for blob.
uploadMetadata(parameterStruct)
Parameter |
Description |
Required |
---|---|---|
key |
The key associated with the blob. |
Yes |
metadata |
Struct that contains the following:
|
Yes |
<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>
Thi method, createPartFiles, is used to break file into multiple block, while uploading a file into multiple blocks.
createPartFiles(parameterStruct)
<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>
The method, commitBlockList, lists down all the commit blocks.
createPartFiles(parameterStruct)
<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>
Sign in to your account