cancel
Showing results for 
Search instead for 
Did you mean: 

Multipart Form-Data - Issue with long file names in content disposition header.

0 Kudos

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.

View Entire Topic
asutoshmaharana2326
Active Participant
0 Kudos

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

0 Kudos

Thank you Asutosh. I will try this and let you know soon. I presume I have to include those apache libraries in the IFlow.

Vijhay Devarajan!

asutoshmaharana2326
Active Participant
0 Kudos

Dear Vijhay,

You don't have to add them as external libs. Just add them as I have mentioned in the code as import statements.

Thanks,

Asutosh

0 Kudos

Hi Ashutosh

It worked! Thank you so much!

Regards

Vijhay Devarajan.