Skip to Content
Technical Articles

How to Connect Azure using SCPI – Upload file to azure blob

Many of you aware that there is no standard adapter like SFTP, SOAP available to connect Azure Cloud with SCPI. So I am writing this post to share how we can get connected with Azure Cloud using SCPI

In this post you will learn how to get connected with Azure Cloud and uploading file to Azure

Azure provides SDK in Java to get connected. As SCPI supports groovy, we can write a simple groovy script to upload any file to azure blob container

For example, I have created a simple flow which uploads csv file to azure folder “trial”

And the script to upload the file is below


def Message processData(Message message) {
    def body = message.getBody(java.lang.String) as String

    String accountName = "your_azure_account_name"
    String accountKey = "your_azure_account_key"
    String storageConnectionString = "DefaultEndpointsProtocol=http;" + "AccountName=" + accountName+ ";" + "AccountKey=" + accountKey

    CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString)
    CloudBlobClient serviceClient = account.createCloudBlobClient()

    CloudBlobContainer container = serviceClient.getContainerReference("azurefoldername/containername")

    String fileName = "filename.csv"
    String fileContent = body
    byte[] fileBytes = fileContent.getBytes()

    CloudBlockBlob blob = container.getBlockBlobReference(fileName)
    blob.uploadFromByteArray(fileBytes, 0, fileBytes.length)



    return message;


you have to replace the accountname, account key and container’s name with your azure’s credentials.

File name can be either static or dynamically populated.

In my groovy script, I have replaced all the credentials and file name as test.csv and azure container name as trial( which is already available in my azure cloud)

Now we have all set to upload a file to Azure cloud. Let’s test it via Postman tool

It is Status 200, which indicates success of uploading the file to Azure. Now let’s check the file in Azure using Azure Storage Explorer


Good Luck !


Questions/Comment and Suggestions are welcome ?

You must be Logged on to comment or reply to a post.
  • My head is going to explode this morning.  I've read so many good technical blogs.  Is there a good business/technical reason for connecting to Azure.

    I know this is the how.   I always ask for more....  What was your business case?

  • /
  • Hi Ansari,


    I've been having some issues that you encountered previously looking at the SCN - with integrating CPI and Commerce Cloud;


    " Bad Request : 400 : HTTP/1.1"

    And not having contact data /adr3mas in ERP for the standard B2B Customer replication iflow.

    Would you be able to share you insights on how you solved those problems?


    Kind Regards.

    • Hi Daniel,

      It is difficult to handle when you don't have adr3mas. What I did was, I commented out adr3mas link in both receiver and sender side of the integration flow and created dummy adr3mas data in the property along with adrmas03 and injected the same with payload. To do that, you have to go though the entire flow and also should be careful with how data is stored in data store and pulled back. requires customization

      • Thanks I appreciate your reply!

        We ended up removing the branch for ADR3MAS, editing the xslt which checked to see if adrmas3, adr3mas and debmas had been received, and adding a conversion to remove the xml utf metadata at one stage where it was storing in the datastore for the missing adr3mas (as it is a reserved keyword in xml).

        We then encountered issues with the standard odata adapter for the B2B Unit as it added URL parameters which couldnt be changed, which was resolved by deleting it and using a new OData V2 adapter, loading a fresh instance of the EDMX, and using ATOM only - as the conversion to JSON added an additional comma which caused incorrect syntax.

        Bit if a nightmare but got a working solution in the end... Not quite the plug and play solution we were hoping for 😀

        Thanks for the tips and guidance. All the best

  • Hi, We have a similar requirement and working towards the same. We need to fetch the data from Azure . We are getting an exception while trying to read blob from Azure and the exception says cause: java.lang.NoClassDefFoundError: javax/crypto/Mac. I belive this is related the JCE policy and not sure if we have the appropriate jar files are present in the JVM. Please provide guidelines in this regards

  • Hello Ansari,

    We are getting the following exception after deployment of iflow.

    javax.script.ScriptException: java.lang.Exception: Host not found@ line 44 in script1.groovy, cause: Host not found

    Can you please guide on this.



    • Actually, it was easier then I thought. I'm processing CSV file from Azure File Storage placed in directory to CPI as text string. To make it even better without fixing a filename this method need to be used: CloudFileDirectory.ListFilesAndDirectories

      code snippet:

          //prepare file
          String fileName = "Test_response.txt" 
          CloudFile file = sampleDir.getFileReference(fileName)
          //get a file
          String fileContent = file.downloadText()
    • Hi, I'm trying the same , connecting from CPI to Azure,

      and getting error while calling

      CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString)

      Error :unable to resolve class CloudStorageAccount 

      do you have some idea to resolve this.

      thanks and regards,


  • Hi Ansari,

    I found your blog very helpful!  I used it in conjunction with the SAP Commerce ‘azurecloud’ extension to write a PNG file to a cloud hot folder (CHF) from a PNG image URL in a digital asset manager (DAM).  I used a different API, but your sample Groovy script was a great starting point!

    Greg Richardson

  • Hi,

    I have used the groovy script mentioned in the blog and changed the Azure account details and created an iflow in CPI.

    I am getting the below error:

    Error Details
    org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[ID-c4050bbe-be45-482f-5677-2cd5-1619827319770-188-1], cause: java.lang.NoClassDefFoundError: javax/crypto/Mac
    Can some one help me with this.