on 07-06-2022 1:22 AM
Hi All
I was trying to implement an excellent piece of code put together by Eng Swee Yeoh from the thread below.
SAP CPI - Forwarding Raw Image Data through Integration Flow | SAP Community
The attachments I'm trying to process have names that are more that 60 characters in length. Due to this I'm running into an issue where content disposition header line breaks for long file names. When I look into the payload, there is two filenames (*0 and *1) as shown below, causing the API call to fail with HTTP 500.
------=_Part_45_448046418.1657064346580
Content-Disposition: form-data; name="FILE";
filename*0=BAT00323X1_20220705_Proctor_55xm_W2821_TV4_ROTATED_FULL_RELEA;
filename*1=SED.zip
----------------------------728856086675725233936972
Content-Disposition: form-data; name="File"; filename="BAT00323X1_20220705_Proctor_55xm_W2821_TV4_ROTATED_FULL_RELEASED.zip"
Content-Type: application/zip
----------------------------728856086675725233936972--
------=_Part_45_448046418.1657064346580
Any help/workaround will be greatly appreciated.
Thank You.
Vijhay Devarajan.
Dear Vijay,
Try using Apache MultipartEntityBuilder to create multipart form data.
import com.sap.gateway.ip.core.customdev.util.Message
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.ContentType;
import org.apache.http.HttpEntity;
Message processData(Message message) {
byte[] bytes = message.getBody(byte[])
// Construct Multipart
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
builder.addBinaryBody("upfile", bytes, ContentType.DEFAULT_BINARY, 'BAT00323X1_20220705_Proctor_55xm_W2821_TV4_ROTATED_FULL_RELEASED.zip');
HttpEntity entity = builder.build();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()
entity.writeTo(outputStream)
message.setBody(outputStream)
String Boundary = entity.getContentType();
message.setHeader('Content-Type', Boundary)
return message
}
Please find below screen dump for reference.
Thanks,
Asutosh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
8 | |
7 | |
5 | |
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.