Hi Everyone, I am Ujala Working with SAP For the last 8 years in different roles like Operation Specialist, Developer, Architecting, design and Developing solutions in Public Cloud, mostly with Azure.

This blog is mainly targeted at developers. If you are someone who has gone through the SAP Help document for the BTP Object store services and didn’t get clarified on the working principle of the SAP BTP Objects store service and how to implement the BTP Object store service in azure using NodeJs.

In this blog series, I will tell you about:

  • What is BTP Object store service
  • Working principle of SAP BTP Object store service and a brief details on the Azure Storage account
  • How to use the BTP Objects store service running in azure using Node JS

Scope of this Blog

This blog will provide details of the SAP BTP Service running on Hyperscaler (Azure Platform).

How you can use the service to work with the blog storage to perform the operation like, Upload data to Blob Storage, List the Blog Storage, and Download the Blob Data.

 

Are there any prerequisites for this blog?

  • SAP BTP Object store Service.
  • Configured the SAP BTP Object store to use the Azure Blob Storage.

More details about creating and configuring the objects store service can be found in the SAP Help portal link: Configure Object Store

 

What is the BTP Object store service?

It is a Blob storage service plan in SAP Business Technology Platform running either in SAP Data centre or Hyperscaler (Azure, AWS. GCP).

You can perform the Create, List, Delete, and Write operations on the blob data.

 

Working Principle

To provide the SAP BTP Object store service, please go through the document below in the SAP Help Portal.

Creating a BTP Object store service running in Azure: Configure Object Store to use Azure Blob Storage | SAP Help Portal

Provision BTP Object store service

There are 4 different data storage options available inside a storage account in azure. account available in Azure.

  • Containers – To store the Blob Objects
  • File Shares: Managed File shares for Cloud and On-Premise deployments
  • Queues: A message store for reliable messaging between application components
  • Tables: A NoSQL Based store

But with the BTP Object store service, only getting the Containers Data storage type in the storage account.

When I create an objects tore service in SAP BTP running on top of the Azure platform, it primarily makes a storage account in Azure and creates a Blob container inside the storage account.

Microsoft provides different ways to access the container created in the storage account.

Access Type 1: By using the Connection String

Access Type 2: By using the Access Keys

Access Type 3: By using the SAS Token (Shared Access Signature)

But with, the SAP BTP service provides only the Access Type 3 possibilities, i.e., using the Shared Access Signature.

NOTE :

More details on the introduction to Blob Storage can be found in the link: Introduction to Blob (object) storage – Azure Storage | Microsoft Docs

Once provisioned service in SAP BTP, below are the important parameters that are part of the credentials object.

  • account_name: Name of the storage account
  • container_name: Name of the container created within the storage account
  • container_uri: Container URI
  • sas_token: Service SAS token needed to access container
  • region: The region in which the storage account and container are created

 

The SAS Token (“sas_token”) that has been given as a part of the credentials was already bound to the container named “container_name” in the credentials section.
The “sas_token” was not an authorisation to everything under the domain; the token was only authorised to visit the container.
So when you create the “BlobServiceClient” object (Following the Documentation), your position was already inside the container. Since you are already inside the container, you can’t perform container operations like the list, create, and delete.

Since the “sas_token” is already bounded to the specific container provided in the environment variable under the credentials section, We can perform the blob-specific activities inside the container, but no container activities can be achieved.

From the above picture, the blob object operations can be only performed on the Green Marked objects; the other things are immutable.

How to use the service programmatically in NodeJs

Step 1: Install the Package

npm install @azure/storage-blob

Step 2: Import the package

You can import the complete package :

const AzureStorageBlob = require("@azure/storage-blob");

Alternatively you can import any specific types:

const { ContainerClient } = require("@azure/storage-blob");

Step 3: Create the Container Client

const sas_url = `${container_uri}?${sas_token}`;
const containerClient = new ContainerClient(sas_url);

Step 4: Blob-Specific Actions

** Some examples are given below

Upload Blob Data

async function uploadBlobData() {
  const content = "Connecting to SAP BTP Object Store running on Microsoft Azure Platform using NodeJS"
  const blobName = 'uploadblob.txt'
  const blockBlobClient = containerClient.getBlockBlobClient(blobName);
  const uploadBlobResponse = await blockBlobClient.upload(content, content.length);
  console.log(`Upload block blob ${blobName} successfully`, uploadBlobResponse.requestId);
}

List Blob

async function listBlobData() {

  let i = 1;
  let iter = containerClient.listBlobsFlat();
  let blobItem = await iter.next();
  while (!blobItem.done) {
    console.log(`Blob ${i++}: ${blobItem.value.name}`);
    blobItem = await iter.next();
  }
}

Download Blob Data

async function downloadBlobData() {

  const BlobClient = containerClient.getBlobClient('<File Name>');
  const data = await BlobClient.download();
  const downloaded = (
      await streamToBuffer(data.readableStreamBody)
    ).toString();
  return res.jsonp(JSON.parse(downloaded));
}

 

I hope you got a basic idea of the flow and how to implement this in NodeJS.

Below I am providing some references that will help to get more ideas on this topic.

Reference:

BTP Object Store: Object Store on SAP BTP | SAP Help Portal

Supported Operations in Azure: Supported Operations | SAP Help Portal

Azure Blob Storage Introduction: Introduction to Blob (object) storage – Azure Storage | Microsoft Docs

Azure SDK for JS: Introduction to Blob (object) storage – Azure Storage | Microsoft Docs

Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x