on 12-18-2020 3:27 PM
Hi
I have a requirement where I need to read the attachment from SF and post to another system which accepts multipart content-type,
can anyone help me on how to design the I-Flow when I get the attachment as Base64 format from SF and I need to send the File with Content type of multipart/form-data.
PFA which I posted through Postman, the same I need to replicate in CPI
Regards
Naveen
Hi navepras,
Please find below the blog with more details:
https://blogs.sap.com/2018/02/09/the-marriage-between-form-data-and-sap-cloud-platform-integration/
If this doesnt work you could directly use the script by engswee.yeoh as mentioned in below answer.
https://answers.sap.com/questions/12716088/sap-cpi---forwarding-raw-image-data-through-integr.html
I am pasting the code mentioned in the answer post.
import com.sap.gateway.ip.core.customdev.util.Message
import javax.activation.DataHandler
import javax.mail.internet.ContentType
import javax.mail.internet.MimeBodyPart
import javax.mail.internet.MimeMultipart
import javax.mail.util.ByteArrayDataSource
Message processData(Message message) {
byte[] bytes = message.getBody(byte[])
// Construct Multipart
MimeBodyPart bodyPart = new MimeBodyPart()
ByteArrayDataSource dataSource = new ByteArrayDataSource(bytes, 'image/jpeg')
DataHandler byteDataHandler = new DataHandler(dataSource)
bodyPart.setDataHandler(byteDataHandler)
bodyPart.setFileName('img.jpg')
bodyPart.setDisposition('form-data; name="files"')
MimeMultipart multipart = new MimeMultipart()
multipart.addBodyPart(bodyPart)
// Set multipart into body
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()
multipart.writeTo(outputStream)
message.setBody(outputStream)
// Set Content type with boundary
String boundary = (new ContentType(multipart.contentType)).getParameter('boundary');
message.setHeader('Content-Type', "multipart/form-data; boundary=${boundary}")
return message
}
you might need to modify as per your requirement.
Hope this helps !
thanks and regards,
Praveen T
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Praveen
Thanks for your help !!
I tried in that script method and i am getting 400 error when i post,
I have added the the encoded format manually and tried to give all the Headers and name in script,but it is not working ..
can you help me in identifying where i made mistake to post the attachment , there are some mandatory inputs like caseid, descriotion, filetype, candidatefile name which i have written in script.
I have attached the Message body and trace as well
Regards
Naveen V
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
76 | |
10 | |
9 | |
8 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.