cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to conusme Form Data in Cloud Integration (CPI)

amysh95
Participant
0 Kudos
197

Hello,


We have come up with one requirement where we have to expose one endpoint in Integration suite where mobile application will send data in form on Form Data because they are sending images along with JSON payload.

Which further we need to update in the hana cloud database (where we need to convert that image in hexadecimal).

The issue is how do we fetch that image and JSON payload separately.

I have come with with one groovy script solution where i'm able to separate the data successfully but during fetching image data i'm encountering data losses (as i'm trying to convert it into hexadecimal/base64).

Input requirement in JSon payload.

 {
"driver_master" : [
{
"DRIVER_NAME" : "Ajay",
"BASE_LOCATION" : "Noida",
"LICENSE_NO" : "111",
"VALID_TO" : "2023-11-23",
"VEHICLE_ALLOWED" : "3",
"VEHICLE_TYPE" : "Two-wheeler",
"LICENSE_IMAGE" : "", <-- this image field data is coming in Form Data not in json
"CREATED_BY" : "SAM",
"CREATED_ON": "2022-01-12"
}
]
}

This is how data in Form Data looks in SAP Integration suite while logging it.

----------------------------824529820432403459873043
Content-Disposition: form-data; name="request"
{
"driver_master" : [
{
"DRIVER_NAME" : "Ajay",
"BASE_LOCATION" : "Noida",
"LICENSE_NO" : "111",
"VALID_TO" : "2023-11-23",
"VEHICLE_ALLOWED" : "3",
"VEHICLE_TYPE" : "Two-wheeler",
"CREATED_BY" : "SAM",
"CREATED_ON": "2022-01-12"
}
]
}
----------------------------824529820432403459873043
Content-Disposition: form-data; name="Driver_image"; filename="Untitled.png"
Content-Type: image/png
<some unreadable binary data>
----------------------------824529820432403459873043-

I'm able to separate these two key's data but white reading image it is not working. i'm facing data loss.

Why I need these data in single go?

Because in one db Table i need to update all these data.

This is how I'm separating these two data in groovy for further processing.

import com.sap.gateway.ip.core.customdev.util.Message; 
import java.util.HashMap;
import java.nio.charset.StandardCharsets;
import org.apache.commons.codec.binary.Base64;

def Message processData(Message message) {

def byteArray = message.getBody((byte[]).class);

def utf8String = new String(byteArray as byte[], StandardCharsets.UTF_8)
def finalOutput = "";

// collecting data in array (form data keys)
def parts = utf8String.findAll(/-{28,}\d+([\s\S]*?)(?=-{28,}\d+|$)/)
def partsWithHashes = parts.collect { it + "##" }


partsWithHashes.each { part ->
if (part.trim()) {
def matcher = part =~ /name="([^"]*)"\s*([\s\S]*?)\s*#{2,}/
println("-------------------")
if (matcher) {
def name = matcher[0][1].trim()
def value = matcher[0][2].trim()

// while converting data loss.
def base64String = Base64.encodeBase64String(value.getBytes(StandardCharsets.UTF_8));
finalOutput = finalOutput + name + "--" + base64String;

if(name.equals("LIC_IMAGE"))
message.setProperty("LIC_IMAGE",base64String)
}
}
}
message.setBody(finalOutput)
return message;
}

I think when I convert the binary data into String at that time only i'm getting data loss.

Can you all guide how to solve this problem, or there is any standard way to handle this requirement.

Thanks

Aman Sharma

Accepted Solutions (0)

Answers (0)