2 weeks ago
Dear Experts,
I am trying to decode a Base64 Encoded pdf in CPI with the standard Base64 Decoder but it looks like the Decoder generating faulty PDF as after saving the content as .pdf it is not opening , showing document is damaged and can't open the file.
I tried to Decode the same Base64 string on Notepad++ and saved the decoded content as .pdf. The file is opening perfectly.
Even I tried replacing the Standard Decoder with Groovy but issue still persists, Please suggest how to resolve this.
Regards,
Arvik
Request clarification before answering.
Hi Arvik,
Maybe I don't understand something here but the provided file is not Base64 encoded, it's a standard PDF file. So if you try to decode it then you receive incorrect data which are not a proper PDF file.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andrzej,
It's my bad as I shared the PDF file instead of the Base64 string.
I am getting this Base64 String from Source , I am performing a PUT call to update the Pdf file (binary) in Ariba.
PUT call is successful and getting back the response but the PDF file is showing blank after opening in ARIBA for this particular input file. Tested with few other input file and for them also the PDF not opening in ARIBA (showing can't open and file is damaged).
Even we tried saving the body from HTTP call as pdf and that is also giving me error.
Similar issue - https://community.sap.com/t5/technology-q-a/send-pdf-through-sap-cpi-pdf-data-lost-after-message-rea...
STEP 1 : Base64 payload as BODY
STEP 2: Decoder from palette
STEP 3: Groovy for building input body
STEP 4: HTTP PUT call
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.Base64;
def Message processData(Message message) {
def body = message.getBody(String);
body = body.replaceAll("\n", "\r\n");
def multipartBody = """------cpi\r\nContent-Disposition: form-data; name="file"; filename="DOC_T_V6.pdf"\r\nContent-Type: application/pdf\r\nContent-Transfer-Encoding: Binary\r\n\r\n""" + body + """\r\n\r\n------cpi--""";
message.setBody(multipartBody);
return message;
}
Sample Input :
Unable to attach the Base64 encoded string as the values exceeds. Shared PDF can be converted to Base64 String and can be used as input.
User | Count |
---|---|
77 | |
30 | |
10 | |
8 | |
8 | |
7 | |
7 | |
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.