Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Dear community,

Did you ever faced the challenge of using a REST service with form-data instead of raw data?
This blog will describe how to deal with this requirement on your preferred cloud integration platform - SAP Cloud Platform Integration -.

The service


In my example, I'm using a service hosted on SAP Cloud Platform. This services is taking a CSV file as request form-data. Once the data is accepted by the service, the records are stored into a custom table. In order to upload your file, the service is handling the form-data (multipart).
Additional documentation about this content-type can be found here: https://www.w3.org/TR/html401/interact/forms.html#h-17.13.4

Sample csv file


FIRSTNAME;LASTNAME;BIRTHDATE
John;Doe;19780405
Jane;Doe;19921015

Testing the service stand alone


It is always a good practice to test your service stand alone before actually implementing it in your middleware system.

Endpoint: SAP SCP Service


Cloud Platform Integration setup


One on one pass through


The idea of this scenario is to get a pass through integration. The payload sent towards CPI will be exactly the same as the one sent to SAP Cloud Platform ("The Service").



Some important remarks about this flow:

  • Allowed Headers

  • Sender connection

  • Receiver connection


Testing via postman:

Endpoint: SAP Cloud Platform Integration endpoint

Sender is multipart upload


The idea of this interface is to be able to send form-data towards CPI, and afterwards handle the data from the attachment (for example convert csv to xml) in your flow. The purpose of this interface is to return the data from the attachment as response to our call.



Some important remarks about this flow:

  • Allowed Headers

  • Sender connection

  • Mime Multipart Decoder


Testing via postman:

Endpoint: SAP Cloud Platform Integration endpoint

Receiver is multipart upload


In this iflow I will set my csv content via a content Modifier, create my body and send the payload as form-data towards "the service" on SAP Cloud Platform.



Some important remarks about this flow:

  • Content Modifier 1 : "SetContent"

  • Content Modifier 2 : "CreateFormData"
    Used to build the multipart
    Header:

    Body:

  • Receiver connection


As this is a timer based interface, I can't test it via Postman. However when the interface is running and you place your traces, you'll be able to see the response as well.



I hope this will help you handling multipart/form-data integrations in the future.
And they lived happily ever after...

Kind regards,
Pieterjan De Schrijver
Cloud integration consultant @ delaware

 
7 Comments
0 Kudos
Interesting use-case, thanks for Blogging!

 
Former Member
0 Kudos
Hi Pieterjan,

 

Really a fantastic blog. Have you ever try to setup an integration flow with a http sender adapter and a mail receiver adapter for the scenario send an email with multipart/form attachment?

I have met trouble that parsing the multipart/form files and set it into the messagebody attachments.

Do you have any experience on that?

 

Thanks and Best Regards

 

Kevin
0 Kudos
Hi Pieterjan,

I have a very similar use case, the only difference is that I am sending raw JPEG image data instead of a CSV file. I have followed along using your "Receiver is multipart upload" step in this blog, but I have not had any luck properly making the request.

I posted a question about this on answers.sap.com which goes into much more detail about my problem. I would really appreciate it if you check out my post here.

The Content-Modifier (that you called "CreateFormData" in your iflow) corrupts my image data and prevents me from properly making my request, likely because it encodes the binary image data as a string. Do you know of a way to format this multipart request properly without corrupting the data?

Thank you for your awesome blog post.

Regards,

Braiden
former_member309269
Participant
0 Kudos
Hi Pieterjan,

I followed the same steps as mentioned in your blog. But I get below error:

HTTP operation failed invoking (vendor URL) with statusCode: 500

 

I tried with both the below content in body of content modifier

----------------------------CPI
Content-Disposition: form-data; name="file"; filename="employment.csv"
Content-Type: text/csv

${in.body}
----------------------------CPI--

 

and

 

----------------------------CPI
Content-Disposition: form-data; name="file"; filename="employment.csv"
Content-Type: application/vnd.ms-excel

${in.body}
----------------------------CPI--

Please let me know what could be wrong.
0 Kudos
Hi Amita,

 

did u found the solution?
i am facing the same problem...

 

thanks
0 Kudos
Hi Amita, Claudio,

 

Did you find the solution for http 500 error?

I am also getting the same error despite following all mentioned steps.

 

Thanks
former_member698594
Discoverer
0 Kudos
Hi Amita,

 

Im facing same problem when invoking HTTP API with internal server error 500.

Did u find the solution?

 

Thanks.
Labels in this area