on 10-26-2014 2:42 PM
Hello,
I'm trying to decode base64 data from an XMLvia User defined function. In the UDF I decoded and wrote it as a file, but the decoded PDF appears corrupt.
Can anyone advise whats wrong here or how this could be done better?
Please advise. Thank you.
Larry.
XML with base64 data:
<SpecialInstructions InstructionType="Instructions">
***Base64 data****
</SpecialInstructions>
***Base64 data**** -> Mapped to var1 of the UDF.
// Import com.sap.engine.lib.xml.util.BASE64Decoder
String f2e = new String(BASE64Decoder.decode(var1.getBytes()));
AbstractTrace trace = container.getTrace();
String location = "/********/test/pdf/";
String fileName = "test1.pdf";
try {
FileWriter fwriter = new FileWriter(location+fileName);
BufferedWriter out = new BufferedWriter(fwriter);
out.write(f2e);
out.close();
} catch (IOException e) {
trace.addWarning("Unable to write file :");
} finally{
trace.addWarning("File Written");
}
return "success";
Hi Aber,
>>String f2e = new String(BASE64Decoder.decode(var1.getBytes()));
You should declare this as byet[] to treat data as binary instead of string (textual)
byte[] f2e = BASE64Decoder.decode(var1.getBytes());
Best Regards,
Praveen Gujjeti
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks again, that did the trick. I will mark it answered, but just a quick question, is there a chance I can use the regular file channel to write this file as a PDF? I have some archiving functions in the adapter module and I need to archive this file written in a different process which is already built in that adapter module..
I'm receiving an order create XML file with PDF encoded(as base64) in the special instructions tag via AS2. The file adapter reads the file and the order details from the XML will be mapped to an IDoc and send to R/3. The PDF needs to decoded and archived in the Seeburger Message tracking database.(via Filestore module as short term archive). The PDF needs to be send to R/3 and it will be loaded as attachment to the sales order.
My plan is to decode the PDF and write it as file to store it in the message tracking database and sending it to the R/3 filesystem so that it can be picked up and loaded in to the Order later.
Let me know if you have better ideas, Thank you.
If I have understood your requirement correct
File Adapter (XML file with base64 pdf and order details) --> PI --> IDOC Order XML to R/3 using IDOC adapter
You can have to receivers for above scenario with a split mapping 1) IDOC 2) File system
For File System receiver you could use a java mapping to read base64 data and then decode to write it to outputstream (TransformationOutput) and the rest file adapter will take care. You can also a use graphical mapping with UDF to create PDF attachment and then use standard SAP payload swapbean in File receiver channel to swap main payload with PDF attachment
Best Regards,
Praveen Gujjeti
Giri,
here is the extract that might help.
import - sap.engine.lib.xml.util.BASE64Decoder
******
GlobalContainer globalContainer = container.getGlobalContainer(); | ||
OutputAttachments oa = globalContainer.getOutputAttachments(); | ||
Attachment attach = oa.create(FileName, MimeType, BASE64Decoder.decode(Base64Data.getBytes())); | ||
oa.setAttachment(attach); |
*****
Larry.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
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.