on 2024 Sep 27 4:06 AM
Hello Experts,
I am now trying doing file decompression (Unzip) within SAP CPi. I unzip two files (.txt and .csv) contained in one ZIP file and store them on an FTP server using the FTP Adapter.
In the FTP Adapter settings, there's a place to set the name of the output files (1 txt file and 1 csv file), but how can I dynamically set the "extension" in this case?
As an example, this is what I expect.
Input Files' (to be unzipped) Name
> AAA.zip (which contains BBB.txt and CCC.csv)
Output Files
>BBB.txt and CCC.csv
(By the way, when I left the file name setting of FTP adapter blank, then the output files came out as BBB and CCC, which means there was no extension.)
(The attached screenshot shows where the file name is set.)
Thank you.
Request clarification before answering.
This may sound weird, but some Windows based FTP servers show only the filename (without extension) by default. Please make sure that is not the case.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
If I understand you correctly, if you leave the File Name field empty the output files are missing the extension, but can you explain why ${header.CamelFileNameOnly} is not working?
In my test scenario, ${header.CamelFileNameOnly} contains the complete path, including the filename and file extension (i.e. zip_file_name/file_name.file_extension).
Assuming that in your case ${header.CamelFileNameOnly} also only contains the file naming excluding extension, I have the following suggestions:
1: Have you tried using ${file:name}?
2: I recently had the requirement to set the target directory dynamically, which I solved by creating a map (in an exchange property) containing the file name as key and the directory as value. Perhaps something similar would also work for the file extension. Assuming that ${header.CamelFileNameOnly} only contains the the file name without extension, you could implement the following steps:
Step 1: use a Groovy script to fill the map. You can check if one of the headers or properties contains the extension type or check the file content for the correct type.
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
// Retrieve properties and headers
def properties = message.getProperties()
def headers = message.getHeaders()
// initiate an empty map
def extension_map = [:]
// Retrieve the filename from the headers
def filename = headers.get("CamelFileNameOnly")
// set the extension
def extension = // implement logic to get file extension
// If the 'Extensions' property already exists, overwrite the empty map with it
if (properties.get("Extensions")) {
extension_map = properties.get("Extensions")
}
// Append new key-value pairs
extension_map[filename] = extension
// Set the updated map (back) to the exchange property
message.setProperty("Extensions", extension_map)
return message;
}
Step 2:
In the File Name field, set: ${header.CamelFileNameOnly}.${property.Extensions[${header.CamelFileNameOnly}]}
I hope that one of these options works for you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
just leave the filename blank and the original file name will set automatically.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
39 | |
15 | |
9 | |
7 | |
5 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.