12

Zip files the right way in SAP CI!

 2 years ago
source link: https://blogs.sap.com/2022/06/20/zip-files-the-right-way-in-sap-ci/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
June 20, 2022 3 minute read

Zip files the right way in SAP CI!

0 2 170

This blog describes the use of CamelFilename header while zipping the files using Zip function  in SAP Cloud Integration ,Build number 6.27.9 !

When using zip function in sap cloud integration make sure to set the header CamelFileName  before the Zip function. And also set the CamelFileName  after the Zip function to another standard/custom header as the CamelFileName header is getting lost while using in the SFTP Adapter. [ Meaning ${header.CamelFileName} does not carry any dynamic value in the adapter configuration.]

1.What if CamelFileName header is not set before the Zip function function.

1.a)  Set Header FileName = Test_${date-with-timezone:now:CET:dd-MM-yyyy}.csv

Using FileName as ${header.FileName} without using .zip extension in the sftp adapter.

IFlow%20without%20CamelFileName%20Set%20before%20ZIP%20function

IFlow without CamelFileName  header set before ZIP function

Let  us try to understand the first case. I have used a sample flow where a Xml  file is converted to csv and we zip the csv file and put it into the SFTP folder.

Using the Content Modifier : Setting the FileName we have created a header FileName

FileName%20Header%20in%20Content%20Modifier

FileName Header in Content Modifier

We set the FileName  in sftp receiver channel as ${header.FileName} [ Note we have not used the .zip extension]

FileName%20in%20SFTP%20Receiver%20Channel

FileName in SFTP Receiver Channel

When we try to hit the IFlow with XML, we have the following csv file in the sftp target folder.

ZIP%20Compressed%20CSV%20File%20in%20SFTP%20Folder

ZIP Compressed CSV File in SFTP Folder

We can see that the .zip type is missing in the file as well as when i tried to open the file it was corrupt. Actual Size of the Proper CSV file was about 237 Kb .. which we will see later .

1.b)  Set Header FileName = Test_${date-with-timezone:now:CET:dd-MM-yyyy}.csv

Using FileName as ${header.FileName}.zip  in the sftp adapter

FileName%20in%20SFTP%20Receiver%20Channel

FileName in SFTP Receiver Channel

In this case you will have a zip file in the SFTP Folder, but  compressed file would have automatically assigned name with type as “File”.

ZIP%20Compressed%20CSV%20File%20with%20type%20as%20File

ZIP Compressed CSV File with type as File

When the target system unzips, looks up for a specific naming format , this could lead to problems as now  the actual intended filename pattern would become a folder under which the compressed file would be saved as type “File” with a automatically assigned file name.

2.What if CamelFileName header is set  before the Zip function

IFlow%20with%20CamelFileName%20Set%20before%20ZIP%20function

IFlow with CamelFileName header set before ZIP function

Now, i have changed the IFlow to set the header ‘ CamelFileName‘ before the ZIP function .

CamelFileName%20set%20in%20Content%20Modifier%20before%20ZIP%20Function

CamelFileName set in Content Modifier before ZIP Function

ZipFileName Header (custom) is set after the zip function  with source as “CamelFileName” header.

ZipFileName%20set%20in%20content%20modifier%20after%20ZIP%20function

ZipFileName set in content modifier after ZIP function

We set the FileName in sftp receiver channel as ${header.ZipFileName} [ Note we have not used the .zip extension]

FileName%20in%20SFTP%20Receiver%20Channel

FileName in SFTP Receiver Channel

When we try to hit the IFlow with XML, we have following zip file in the sftp target folder. Also the unzip file contains the same file name pattern as intended.

Zip%20file%20and%20Unzipped%20file%20with%20proper%20Filename%20pattern

Zip file and Unzipped file with proper Filename pattern

The explanation for above behavior could be due to the fact that  CamelFileName header is generated after zip compression and assigned a random value if not assigned before. I leave it upto the readers to build a basic flow and use simulation to understand the same.

One more behaviour is that CamelFileName header is lost when used in SFTP Adapter. I don’t have a concrete answer for that atleast now.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK