Mx 8 - multipart/form-data - change the content-type of a specific part

1
Hi there, I am using a call REST action in Mendix 8 that sends form-data to an API. I am sending a filedocument (.pdf) in the API call:     Mendix translates this to the following part: ------=_Part_7_1147861337.1568979786152 Content-Type: application/octet-stream Content-Disposition: form-data; name="file"; filename="DocumentPDF.pdf" The problem here is that the API now receives my PDF as an octet-stream. Does anyone know how I can change application/octet-stream in something else? I've tried overwriting the Content-Type of the part by adding HTTP headers and extra parts but this is not working. Any ideas? Thanks!    
asked
5 answers
1

Does it need to be a multipart for any specific reason? You can also send the file as base64 encoded string in the form attributes/properties.

answered
1

Hi all,

Sorry for the late response.

Here is the java action that we are using in the project: https://www.dropbox.com/s/5zem8nzx2y2235a/PostFileMultipartFormdata.mpk?dl=0

Please note that the code might not be perfect. It is not unit tested and code reviewed properly.

Kind regards,

Tim

answered
0

As far as I know the Call Rest action does not (yet) support multipart requests. You can only send a FileDocument using Binary for the request.

The RestServices module does support requests where the file is part of a multipart form submit request.

answered
0

I am now using a custom Java action to solve the content-type issue with sending form-data files. Please let me know if you want me to share it with you.

answered
0

Replying to this old post, because Studio Pro 9.3 has just been released with a new feature: you can now specify headers for the different parts of the form-data request.

answered