Steps to access Azure Blob Storage via REST API from SAP CPI using Azure Storage Adapter and SAP PO/PI using http adapter
2023-11-17 13:43:33 Author: blogs.sap.com(查看原文) 阅读量:31 收藏

Introduction: This document describes how to access Azure blob storage via APIs from CPI/ PO/PI, including steps required at Azure side to give access to an external system like CPI.

Let’s set up Azure blob storage first.

Make sure that you have proper resource group assigned to your user id and storage account created under that resource group on Azure Portal.

  • Give any name in small case and click on create.
  • Click on created container.

  • Now click on Shared Access Token, select stored access policy created earlier from drop down list and click on generate SAS token and URL at bottom.

Copy SAS url

https://<storageAccount>.blob.core.windows.net/cpiblob?st=2023-11-16T04:31:42Z&se=2023-11-16T12:31:42Z&si=PolicyforCPIblob&sv=2022-11-02&sr=c&sig=2mfvSkWmlqL4dxgfsdnsdlAB9%2FtS0gCwBUtEaRmaL9YP8AA%3D

Copy SAS Token to use in CPI Azure Storage Adapter

st=2023-11-16T04:31:42Z&se=2023-11-16T12:31:42Z&si=PolicyforCPIblob&sv=2022-11-02&sr=c&sig=2mfvSkWmlqL4dxgfsdnsdlAB9%2FtS0gCwBUtEaRmaL9YP8AA%3D

If you want to access blob storage using http adapter of SAP PO/PI/ CPI or any testing tool, then here you go

Now we have URL to access that container.

Let’s divide the URL into 3 parts

Part1- https://<storageAccount>.blob.core.windows.net/<ContainerName>?st=2023-11-16T04:31:42Z&se=2023-11-16T12:31:42Z&si=PolicyforCPIblob&sv=2022-11-02&sr=c&sig=2mfvSkWmlqL4dxgfsdnsdlAB9%2FtS0gCwBUtEaRmaL9YP8AA%3D

Part3- https://<storageAccount>.blob.core.windows.net/<ContainerName>?st=2023-11-16T04:31:42Z&se=2023-11-16T12:31:42Z&si=PolicyforCPIblob&sv=2022-11-02&sr=c&sig=2mfvSkWmlqL4dxgfsdnsdlAB9%2FtS0gCwBUtEaRmaL9YP8AA%3D

Part2- as per below table
Activity Azure Blob Permission (in access policy) http Operation Header Part2
Read the file names from storage List Get ?restype=container&comp=list&
Read file from storage Read Get /<FileName with extension>?
Create File Create Put x-ms-blob-type=blockblob /<FileName with extension>?
Append File Add Put x-ms-blob-type=appendblob /<FileName with extension>?comp=appendblock
Delete File Delete Delete x-ms-blob-type=blockblob /<FileName with extension>?
Overwrite file Write Put x-ms-blob-type=blockblob /<FileName with extension>?

***Append file option is not available with older version of blob

let’s take an example, if we need to create a file with name test.txt in the blob using http api,

Then…

Part1-  https: //<storageAccount>.blob.core.windows.net/<ContainerName>

Here we are using container cpiblob

Part2- /<FileName with extension>?

Here we are using filename test.txt

Part3- st=2023-11-16T04:31:42Z&se=2023-11-16T12:31:42Z&si=PolicyforCPIblob&sv=2022-11-02&sr=c&sig=2mfvSkWmlqL4dxgfsdnsdlAB9%2FtS0gCwBUtEaRmaL9YP8AA%3D

So, complete URL is

https: //<storageAccount>.blob.core.windows.net/cpiblob/test.txt? st=2023-11-16T04:31:42Z&se=2023-11-16T12:31:42Z&si=PolicyforCPIblob&sv=2022-11-02&sr=c&sig=2mfvSkWmlqL4dxgfsdnsdlAB9%2FtS0gCwBUtEaRmaL9YP8AA%3D

Above URL can be used in any receiver http or rest adapter to create a file in blob storage.

Let’s create an iflow in CPI to write a file into blob using Azure Storage Adapter.

Create an iFlow where message will come over http protocol with header “FileName”, iflow will read payload and name of the file from FileName header and write the file in blob storage with the same name and data.

  • Create a security material with secure parameter option.
  • Give any proper name and paste SAS token (Copied earlier from Azure Portal) in secure parameter and deploy it.
  • Create connection to receiver with Azure Adapter and Blob Type message protocol.
  • Put Security Material name as Token Alias.
  • Set operation as Upload Block Blob, Put your Storage Acccount Name, Container Name and put property BlobPath in BlobPath.

  • Deploy it
  • Let’s test it from Postman
  1.         Write something in body
  2.         Set FileName Header with Test.txt value
  3. Click on send and you can see file created in blob storage

Conclusion: This document explains setting at Azure side for blob access via API and how to use Azure storage adapter in CPI.


文章来源: https://blogs.sap.com/2023/11/17/steps-to-access-azure-blob-storage-via-rest-api-from-sap-cpi-using-azure-storage-adapter-and-sap-po-pi-using-http-adapter/
如有侵权请联系:admin#unsafe.sh